Being able to put php directives in httpd.conf and have them work on a per-directory or per-vitual host basis is just great. Now there's another aspect which might be worth being aware of:
A php.ini directive put into your apache conf file applies to php when it runs as an apache module (i.e. in a web page), but NOT when it runs as CLI (command-line interface).
Such feature that might be unwanted by an unhappy few, but I guess most will find it useful. As far as I'm concerned, I'm really happy that I can use open_basedir in my httpd.conf file, and it restricts the access of web users and sub-admins of my domain, but it does NOT restrict my own command-line php scripts...
How to change configuration settings
Running PHP as an Apache module
When using PHP as an Apache module, you can also change the configuration settings using directives in Apache configuration files (e.g. httpd.conf) and .htaccess files. You will need "AllowOverride Options" or "AllowOverride All" privileges to do so.
There are several Apache directives that allow you to change the PHP configuration from within the Apache configuration files. For a listing of which directives are PHP_INI_ALL, PHP_INI_PERDIR, or PHP_INI_SYSTEM, have a look at the List of php.ini directives appendix.
-
php_valuename value -
Sets the value of the specified directive. Can be used only with PHP_INI_ALL and PHP_INI_PERDIR type directives. To clear a previously set value use none as the value.
Note: Don't use
php_valueto set boolean values.php_flag(see below) should be used instead. -
php_flagname on|off -
Used to set a boolean configuration directive. Can be used only with PHP_INI_ALL and PHP_INI_PERDIR type directives.
-
php_admin_valuename value -
Sets the value of the specified directive. This can not be used in .htaccess files. Any directive type set with
php_admin_valuecan not be overridden by .htaccess. To clear a previously set value use none as the value. -
php_admin_flagname on|off -
Used to set a boolean configuration directive. This can not be used in .htaccess files. Any directive type set with
php_admin_flagcan not be overridden by .htaccess.
Example #1 Apache configuration example
<IfModule mod_php5.c> php_value include_path ".:/usr/local/lib/php" php_admin_flag safe_mode on </IfModule> <IfModule mod_php4.c> php_value include_path ".:/usr/local/lib/php" php_admin_flag safe_mode on </IfModule>
PHP constants do not exist outside of PHP. For example, in httpd.conf you can not use PHP constants such as E_ALL or E_NOTICE to set the error_reporting directive as they will have no meaning and will evaluate to 0. Use the associated bitmask values instead. These constants can be used in php.ini
Changing PHP configuration via the Windows registry
When running PHP on Windows, the configuration values can be modified on a per-directory basis using the Windows registry. The configuration values are stored in the registry key HKLM\SOFTWARE\PHP\Per Directory Values, in the sub-keys corresponding to the path names. For example, configuration values for the directory c:\inetpub\wwwroot would be stored in the key HKLM\SOFTWARE\PHP\Per Directory Values\c\inetpub\wwwroot. The settings for the directory would be active for any script running from this directory or any subdirectory of it. The values under the key should have the name of the PHP configuration directive and the string value. PHP constants in the values are not parsed. However, only configuration values changeable in PHP_INI_USER can be set this way, PHP_INI_PERDIR values can not.
Other interfaces to PHP
Regardless of how you run PHP, you can change certain values at runtime of your scripts through ini_set(). See the documentation on the ini_set() page for more information.
If you are interested in a complete list of configuration settings on your system with their current values, you can execute the phpinfo() function, and review the resulting page. You can also access the values of individual configuration directives at runtime using ini_get() or get_cfg_var().
How to change configuration settings
02-Feb-2008 05:25
11-Jul-2007 08:18
To change the configuration for php running as cgi those handy module commands won't work.. The work-around is being able to tell php to start with a custom php.ini file.. configured the way you want.
With multiple custom php.ini files
-------------------------------------------
/site/ini/1/php.ini
/site/ini/2/php.ini
/site/ini/3/php.ini
--
The trick is creating a wrapper script to set the location of the php.ini file that php will use. Then it exec's the php cgi.
shell script /cgi-bin/phpini.cgi
-------------------------------------------
#!/bin/sh
export PHPRC=/site/ini/1
exec /cgi-bin/php5.cgi
--
Now all you have to do is setup Apache to run php files through the wrapper script instead of just executing the php cgi.
In your .htaccess or httpd.conf file
-------------------------------------------
AddHandler php-cgi .php
Action php-cgi /cgi-bin/phpini.cgi
--
So to change the configuration of php you just need to change the PHPRC variable to point to a different directory containing your customized php.ini.. You could also create multiple shell wrapper scripts and create multiple Handler's+Actions in .htaccess..
in your .htaccess
-------------------------------------------
AddHandler php-cgi1 .php1
Action php-cgi1 /cgi-bin/phpini-1.cgi
AddHandler php-cgi2 .php2
Action php-cgi2 /cgi-bin/phpini-2.cgi
AddHandler php-cgi3 .php3
Action php-cgi3 /cgi-bin/phpini-3.cgi
--
The only caveat here is that it seems like you would have to rename the file extensions, but there are ways around that too ->
http://www.askapache.com/php/custom-phpini-tips-and-tricks.html
09-Jul-2007 06:09
@ pgl: As the documentation says:
"To clear a previously set value use none as the value."
Works fine for me.
27-Jun-2007 03:59
It is not possible to unset a config option using php_value. This caused me problems with auto_prepend_file settings where I wanted to have a global file auto included, with an exception for only one site. The solution used to be to use auto_prepend_file /dev/null, but this now causes errors, so I just create and include blank.inc now instead.
