14.2. Keeping Passwords Out of Your Site Files
While this technique removes passwords from the source code of your pages, it does make them available in other places that need to be protected. Most importantly, make sure that there are no publicly viewable pages that call phpinfo( ). Because phpinfo( ) displays environment variables available to scripts, it displays the passwords put into environment variables.
Next, especially if you are in a shared hosting setup, make sure that the environment variables are set in such a way that they are available only to your virtual host, not to all shared hosting users. With Apache, you can do this by setting the variables in a separate file from the main configuration file:
SetEnv MYSQL_USER "susannah" SetEnv MYSQL_PASSWORD "y23a!t@ce8"
Inside the <VirtualHost> directive for the site in the main configuration file, include this separate file as follows:
Make sure that the separate file that contains the passwords (e.g., /usr/local/apache/database-passwords) is not readable by any users other than the one that controls the appropriate virtual host. When Apache starts up and is reading in configuration files, it's usually running as root, so it is able to read the included file.
14.2.4. See Also
Documentation on Apache's Include directive at http://httpd.apache.org/docs/mod/core.html#include.
Copyright © 2003 O'Reilly & Associates. All rights reserved.