PHP: Runtime Configuration - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

How to change configuration settings Bug reports

Last updated: Fri, 26 Jan 2007

view this page in

# Глава 9. Runtime Configuration

# The configuration file

The configuration file (called `php3.ini` in PHP 3, and simply `php.ini` as of PHP 4) is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the CGI and CLI version, it happens on every invocation.

`php.ini` is searched in these locations (in order):

- SAPI module specific location (`PHPIniDir` directive in Apache 2, `-c` command line option in CGI and CLI, `php_ini` parameter in NSAPI, `PHP_INI_PATH` environment variable in THTTPD)

- The `PHPRC` environment variable. Before PHP 5.2.0 this was checked after the registry key mentioned below.

- As of PHP 5.2.0, the following registry locations are searched in order: `HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath\x.y.z`, `HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath\x.y` and `HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath\x`, where x, y and z mean the PHP major, minor and release versions.

- `HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath` (Windows Registry location)

- Current working directory (except CLI)

- The web server's directory (for SAPI modules), or directory of PHP (otherwise in Windows)

- Windows directory (`C:\windows` or `C:\winnt`) (for Windows), or `--with-config-file-path` compile time option

If `php-SAPI.ini` exists (where SAPI is used SAPI, so the filename is e.g. `php-cli.ini` or `php-apache.ini`), it's used instead of `php.ini`. SAPI name can be determined by php_sapi_name().

> Замечание: The Apache web server changes the directory to root at startup causing PHP to attempt to read `php.ini` from the root filesystem if it exists.

The `php.ini` directives handled by extensions are documented respectively on the pages of the extensions themselves. The list of the core directives is available in the appendix. Probably not all PHP directives are documented in the manual though. For a complete list of directives available in your PHP version, please read your well commented `php.ini` file. Alternatively, you may find the the latest `php.ini` from CVS helpful too.

Пример 9-1. `php.ini` example

    ; any text on a line after an unquoted semicolon (;) is ignored
    [php] ; section markers (text within square brackets) are also ignored
    ; Boolean values can be set to either:
    ;    true, on, yes
    ; or false, off, no, none
    register_globals = off
    track_errors = yes

    ; you can enclose strings in double-quotes
    include_path = ".:/usr/local/lib/php"

    ; backslashes are treated the same as any other character
    include_path = ".;c:\php\lib"

Since PHP 5.1.0, it is possible to refer to existing .ini variables from within .ini files. Example: `open_basedir = ${open_basedir} ":/new/dir"`.

add a note User Contributed Notes
Runtime Configuration
cduke420 at gmail dot com
07-Jan-2007 10:16
`[ When php run as Apache Module ]
DOCUMENT_ROOT .htaccess
+======================================+
SetEnv PHPRC /home/user/dir-containing-phpinifile
+======================================+
[ When php run as CGI ]
Place your php.ini file in the dir of your cgi'd php binary, in this case /cgi-bin/
DOCUMENT_ROOT .htaccess
+======================================+
AddHandler php-cgi .php .htm
Action php-cgi /cgi-bin/php5.cgi
+======================================+
[ PHP run as cgi with wrapper (for FastCGI) ]
Your wrapper script should look something like:
+======================================+
#!/bin/sh
export PHP_FCGI_CHILDREN=3
exec /user/htdocs/cgi-bin/php.cgi -c /home/user/php.ini
+======================================+
original article:
http://www.askapache.com/2007/php/custom-phpini-tips-and-tricks.html`
Alonso
18-Nov-2006 04:21
`Setting php.ini location for PHP working as Apache module (without use SetEnv directive in httpd.conf):
Before start Apache, set the PHPRC environment variable to the path where php.ini should be loaded, for example:
PHPRC=/etc/php4/apache-another-path
export PHPRC
In Debian we can do this way:
In /etc/init.d/apache (the script that loads apache web server) we have this line:
ENV="env -i LANG=C PATH=/bin:/usr/bin:/usr/local/bin"
Set to this:
ENV="env -i LANG=C PATH=/bin:/usr/bin:/usr/local/bin PHPRC=/etc/php4/apache-another-path"
Then wen you reload apache the php.ini will be loaded in the directory configured in PHPRC environment variable.`
Trevor Blackbird > yurab.com
11-Apr-2006 03:50
`You can use also use the predefined PHP_SAPI constant instead of php_sapi_name().`
c dot affolter at stepping-stone dot ch
13-Mar-2006 05:38
`For those people who want to use the PHPRC environment variable:
You have to specify the path to the directory containing your php.ini, not the direct path to the php.ini.
Example (php.ini resides in /your/path/php.ini):
right:
export PHPRC=/your/path
wrong:
export PHPRC=/your/path/php.ini`
randy AT rcs-comp DOT com
26-May-2005 12:47
`(copied from another page)
Please note that the SetEnv PHPRC "directory/to/phpini/" only works when using PHP as CGI, but _not_ when you use the PHP Apache Module!`
Jorrit Schippers
26-May-2004 04:33
`For IIS users: If you experience high parsetimes, try to set output_buffering to On. IIS has problems with scripts outputting many small pieces of text, and with output_buffering = On, PHP sends the whole page to IIS in one piece.`
add a note
How to change configuration settings Bug reports

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST