PHP: Hypertext Preprocessor (original) (raw)
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**[INI_ALL](info.constants.php#constant.ini-all)
**, [INI_PERDIR](info.constants.php#constant.ini-perdir)
, or [INI_SYSTEM](info.constants.php#constant.ini-system)
, have a look at theList of php.ini directives appendix.
php_value
name
value
Sets the value of the specified directive. Can be used only with [INI_ALL](info.constants.php#constant.ini-all)
and [INI_PERDIR](info.constants.php#constant.ini-perdir)
type directives. To clear a previously set value use none
as the value.
Note: Don't use
php_value
to set boolean values.php_flag
(see below) should be used instead.
php_flag
name
on|off
Used to set a boolean configuration directive. Can be used only with [INI_ALL](info.constants.php#constant.ini-all)
and**[INI_PERDIR](info.constants.php#constant.ini-perdir)
** type directives.
php_admin_value
name
value
Sets the value of the specified directive. This can not be used in .htaccess files. Any directive type set with php_admin_value
can not be overridden by .htaccess or ini_set(). To clear a previously set value use none
as the value.
php_admin_flag
name
on|off
Used to set a boolean configuration directive. This can not be used in .htaccess files. Any directive type set with php_admin_flag
can not be overridden by .htaccess or ini_set().
Example #1 Apache configuration example
php_value include_path ".:/usr/local/lib/php" php_admin_flag engine on php_value include_path ".:/usr/local/lib/php" php_admin_flag engine onCaution
PHP constants do not exist outside of PHP. For example, inhttpd.conf you can not use PHP constants such as [E_ALL](errorfunc.constants.php#constant.e-all)
or [E_NOTICE](errorfunc.constants.php#constant.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 keyHKLM\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**[INI_USER](info.constants.php#constant.ini-user)
** can be set this way, [INI_PERDIR](info.constants.php#constant.ini-perdir)
values can not, because these configuration values are re-read for each request.
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 thephpinfo() function, and review the resulting page. You can also access the values of individual configuration directives at runtime using ini_get() orget_cfg_var().
Found A Problem?
contrees.du.reve at gmail dot com ¶
17 years ago
`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...
`
5 months ago
If a directive has beeen set many times in different places, the precedence is as follows in descending order php-fpm php_*[foo] = bar command line argument -d foo=bar environment variable foo=bar and referenced as ${foo} in php.ini php.ini foo=bar