PHP

We recently searched high and low for an elegant way to define PHP directives on a per domain basis. We use Lighttpd web server, and therefore .htaccess rules and configurations are unavailable. The reason for the requirement of granular PHP directive settings, is we have clients that want to host multiple web applications on a single cloud server, but want PHP to perform slightly different for each of their applications. A concrete example of this is, a PHP application may be quite old, and require register_globals on (we know, this is bad practice and we frown upon it), while the rest of the clients applications can have register_globals off. Another great example for us internally, is to be able to define a PHP log file for each domain independently, instead of a single monstrous PHP log file for the entire cloud server.

PHP user ini files to the rescue! User PHP ini files allow you to define PHP directives on a per directory basis, which is extremely powerful and flexible. The only caveat is that you must be running PHP 5.3.0 or greater. To get user php ini files running simply modify your main/base php.ini file and add the following two directives:

user_ini.filename = .php.user.ini
user_ini.cache_ttl = 60

The first directive, user_ini.filename specifies the file name that PHP searches for in each directory to process PHP directives. If set to an empty string, PHP doesn’t scan at all. The default is .user.ini, we prefer .php.user.ini, but you may use whatever file name structure you wish. The second directive user_ini.cache_ttl controls how often user INI files are re-read. The default is 300 seconds (5 minutes), but we prefer a slightly faster refresh, so our user_ini.cache_ttl is 60 (1 minute).

Once the above two directives are in your main/base php.ini, simply create your user ini files, and put whatever PHP directives you want to override in the files. You may have to wait up to user_ini.cache_ttl for your custom directives to take effect, but you will NOT have to restart your web server; wooo hoo!

If you have any questions or further comments, don’t be shy; let us know.