Should DB_HOST be changed to 127.0.0.1?
P粉514001887
2023-08-26 17:50:38
<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>
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).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 serverWhat you need to read about Laravel Project Deployment