Using custom
php.ini
files is pretty straighforward for CGI/FastCGI based PHP installations but it isn't feasible when running PHP as Apache module (mod_php) because the whole server runs a single instance of the PHP interpreter.
My advice:
- Set from PHP itself as many settings as you can:
ini_set('memory_limit', '16M'); date_default_timezone_set('Europe/Madrid') ...
In other words, directives that can be changed at runtime. - Set the rest of stuff from per-directory Apache setting files (aka
.htaccess
):php_flag short_open_tag off php_value post_max_size 50M php_value upload_max_filesize 50M
i.e., settings that need to be defined before the script starts running
Please have a look at the Runtime Configuration for further details.
Sometimes, you'll actually need different settings in development and production. There're endless ways to solve that with PHP code (from creating a boolean constant from the
$_SERVER['HTTP_HOST']
variable to just having a config.php
file with different values) but it's trickier with .htaccess
. I normally use the <IfDefine>
directive:<IfDefine DEV-BOX>
#
# Local server directives
#
SetEnv DEVELOPMENT "1"
php_flag display_startup_errors on
php_flag display_errors on
php_flag log_errors off
#php_value error_log ...
</IfDefine>
<IfDefine !DEV-BOX>
#
# Internet server directives
#
php_flag display_startup_errors off
php_flag display_errors off
php_flag log_errors on
php_value error_log "/home/foo/log/php-error.log"
</IfDefine>
... where
DEV-BOX
is a string I pass to the local Apache command-line:C:\Apache24\bin\httpd.exe -D DEV-BOX
If you run Apache as service, the
-D DEV-BOX
bit can be added in the Windows registry, e.g.:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Apache2.4\Parameters\ConfigArgs
Comments
Post a Comment