search

Home  >  Q&A  >  body text

Should DB_HOST be changed to 127.0.0.1?

<p>So I'm using XAMPP and Laravel 5.x with PHP 7.4 and when I load my local server, I run into an error and can't access the database on my system. When I searched online, the answer I found said to change the local <code>DB_HOST</code> address in the <code>database.php</code> file to <code>127.0.0.1< ;/code> instead of setting it to localhost because MYSQL will use TCP instead of a UNIX socket to connect. Will it cause problems if I push this change to staging or production servers? </p>
P粉514001887P粉514001887505 days ago653

reply all(2)I'll reply

  • P粉587780103

    P粉5877801032023-08-27 11:05:26

    Laravel uses the DotEnv library to configure different environments. You can follow the Laravel documentation to generate .env files for each environment (local and development server).

    reply
    0
  • P粉986860950

    P粉9868609502023-08-27 10:45:07

    On a real server, you need to connect to the database server that contains the database used by the application, Therefore the .env configuration related to the database needs to be changed to the actual database server

    1

    2

    3

    4

    5

    DB_HOST=[这里是数据库服务器IP]

    DB_PORT=3306

    DB_DATABASE=[数据库名称]

    DB_USERNAME=[用户名]

    DB_PASSWORD=[用户密码]

    What you need to read about Laravel Project Deployment

    reply
    0
  • Cancelreply