Home > Article > PHP Framework > BUG (environment variable problem) caused by laravel project release
The content of this article is about the BUG (environment variable problem) caused by the release of the laravel project. It has certain reference value. Friends in need can refer to it. I hope it will be useful to you. Helps.
After a certain release of the laravel project, an error occurred suddenly when connecting to the database in the project, but it was OK to connect to the machine using the same database account and password.
Temporary solution
After a short period of investigation, the reason was not found. The original database password DB_PASSWORD=abcde#142!*, change the database password to DB_PASSWORD After =abcde2019, it will return to normal.
Troubleshooting Ideas
After changing the password, the database can be connected normally, which shows that it is a password problem. At the same time, the same password fails to access the database in the project but can be accessed on the machine. If successful, it can be determined that the password problem is caused by environmental problems.
Print the log of the database connection configuration in the project, as follows:
Array ( [driver] => mysql [host] => xxx [port] => xxx [database] => xxx [username] => xxx [password] => abcde [unix_socket] => [charset] => utf8mb4 [collation] => utf8mb4_unicode_ci [prefix] => [strict] => 1 [engine] => )
The visible password configuration in env is DB_PASSWORD=abcde#142!*
, but in the PHP code The database password read in is configured as abcde
. It can be seen that the content behind # is considered to be a comment in the code and thus ignored.
Continue to check the jenkins release log and find a piece of log output:
Package operations: 0 installs, 3 updates, 0 removals - Updating vlucas/phpdotenv (v2.5.2 => v2.6.0): Downloading (connecting...)Downloading (0%) Downloading (15%)Downloading (100%)
During the release process, there is an upgrade of a dependent package.
Look at the documentation of vlucas/phpdotenv and see the following instructions:
Comments
You can comment your .env file using the # character. E.g.
# this is a comment VAR="value" # comment VAR=value # comment
Solution
.env file, add double quotes to the password field, such as DB_PASSWORD="abcde#142!*", and then everything returns to normal.
It is recommended that "" be added to the configuration of environment variables in the .env file to avoid unexpected disasters.
The above is the detailed content of BUG (environment variable problem) caused by laravel project release. For more information, please follow other related articles on the PHP Chinese website!