BUG caused by the release of laravel project (environment variable problem)

01-28-2024

What this article brings to you is about the BUG (environmental variable problem) caused by the release of laravel project, which has certain reference value. Friends who need it can refer to it and hope to help you.

After the release of laravel project, the connection database in the project suddenly reported an error, but it is ok to connect on the machine with the same database account password.

Temporary solution

After a short period of investigation, the reason was not found. The original database password was DB_PASSWORD=abcde#142! *, after changing the database password to DB_PASSWORD=abcde2019, it returned to normal.

Thinking of investigation

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 failed to access the database in the project and can be accessed successfully on the machine, which can be judged to be a password problem caused by environmental problems.

Print the log of 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] => )

Visible password configuration in env is DB_PASSWORD=abcde#142! *, but the database password read in the PHP code is configured as abcde, which can be seen as a comment in the content code after #, thus being ignored.

Continue to check jenkins publishing log, and find a 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 a dependency package upgrade.

Check 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 quotation marks to the password field, such as DB_PASSWORD="abcde#142! * ",and then everything is back to normal.

It is suggested that ""should be added to the configuration of environment variables in the. env file to avoid unexpected disasters.

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us