- Return array (
- 'Database' => array (
- 'Host' => '2017. 168.0.1 ',
- 'User' => 'admin ',
- 'Password' => 'e1bfd762321e409cee4ac0b6e841963c ',
- ),
- );
- ?>
Sometimes for some reason, such as code review, or cooperative development, a third party needs to obtain the read permission of the code version repository. once authorized, the database address, user name, sensitive information such as passwords is exposed. Of course, you can also not save the configuration file in the code version repository, but instead write a document to describe it, but I do not like this method, because the code itself is incomplete.
How can this problem be solved? The most direct method is to remove sensitive information from the code and save it elsewhere. Where can I save it? There are many options, such as setting through fastcgi_param of nginx:
- Return array (
- 'Database' => array (
- 'Host' => $ _ SERVER ['database _ host'],
- 'User' => $ _ SERVER ['database _ username'],
- 'Password' => $ _ SERVER ['database _ password'],
- ),
- );
- ?>
In addition, you can use the env command of php-fpm to set: Env [DATABASE_HOST] = 192.168.0.1env [DATABASE_USERNAME] = administratorenv [DATABASE_PASSWORD] = e1bfd762321e409cee4ac0b6e841963c
One thing to note is that this setting must be placed in the php-fpm.conf of the main configuration file, not in the sub-configuration file of the include instruction setting, otherwise an error will be reported: "Array are not allowed in the global section". in addition, although set through env, the result is still in $ _ SERVER, rather than $ _ ENV.
Note: @ Laruence reminds me that if the configuration information is set through fastcgi_param of nginx, when nginx interacts with php, it will bring about a large amount of data transmission (it seems that it is more advantageous to use the php-fpm env). laruence recommends using independent extensions, such as "hidef 」.
The nginx and php-fpm configuration files are used to solve the problem. they are only valid for the Web. if you run them through the command line, you cannot obtain relevant information in $ _ SERVER, however, this is not difficult. you only need to write a common script to match the nginx or php-fpm configuration file, and then you can dynamically map the information to the command line environment, let's leave it to everyone.
The rest of the work is how to ensure the security of nginx or php-fpm configuration files. However, compared with the code, nginx or php-fpm configuration files do not require the permissions of many people, therefore, it is easier to manage. |