You get a bonus - 1 coin for daily activity. Now you have 1 coin

Apache: setting PHP options and parameters for individual sites

Practice



PHP reads its settings from the php.ini file, where you can describe options and parameters for the PHP module to use for all sites. That is, php.ini specifies options that apply globally to all sites served by this web server.

But it is often necessary to set these options for individual sites specifically. For example, to override the path to the log file or to specify a larger value for the memory allowed for use by the PHP process... and so on.

If we're talking about the Apache server, we have two ways to do this.


1) The first way: through the Apache configuration.

Open the configuration file of the desired site and, inside the "<VirtualHost...>" block, specify the necessary options for this host.

Options are specified using the following four keywords:
  • php_value parameter value. Use this option to specify non-boolean (i.e., not "on/off") values. Boolean values are set with the next option.
  • php_flag parameter on|off. Used to set a boolean option value.
  • php_admin_value parameter value. The same as php_value, but it unconditionally overrides the same option specified in .htaccess (i.e., php_admin_value has higher priority than php_value in the .htaccess file).
  • php_admin_flag parameter on|off. The same as php_flag, but it unconditionally overrides the same option specified in .htaccess.


Examples:
<VirtualHost ...>
php_value error_log "/www/mysite/log/errors.log"
php_flag display_errors Off
php_admin_value memory_limit 32M
</VirtualHost>



2) The second way: through the .htaccess file.

The syntax is the same, except that the php_admin_value and php_admin_flag options do not work in the .htaccess file.


Example:
php_value error_log "/www/mysite/log/errors.log"
php_flag display_errors Off



PS/Note. In the Apache configuration files and .htaccess you CANNOT use PHP constants (for example, E_ALL for error_reporting), because these constants are not available to Apache, i.e. they don't exist for Apache. Instead, use numeric values obtained via binary combination (you can read about them in the PHP help).

Applies to: Apache 2.x; PHP 5.2.x and above

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)