PHP 5.4.33 Released

The configuration file

The configuration file (php.ini) 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 versions, it happens on every invocation.

php.ini is searched for 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 location of the php.ini file can be set for different versions of PHP. The following registry keys are examined in order: [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z], [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x], where x, y and z mean the PHP major, minor and release versions. If there is a value for IniFilePath in any of these keys, the first one found will be used as the location of the php.ini (Windows only).
  • [HKEY_LOCAL_MACHINE\SOFTWARE\PHP], value of IniFilePath (Windows only).
  • 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 the SAPI in use, so, for example, php-cli.ini or php-apache.ini), it is used instead of php.ini. The SAPI name can be determined with php_sapi_name().

Nota:

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.

Using environment variables can be used in php.ini as shown below.

Example #1 php.ini Environment Variables

; PHP_MEMORY_LIMIT is taken from environment
memory_limit = ${PHP_MEMORY_LIMIT}

The php.ini directives handled by extensions are documented on the respective pages of the extensions themselves. A list of the core directives is available in the appendix. Not all PHP directives are necessarily documented in this manual: for a complete list of directives available in your PHP version, please read your well commented php.ini file. Alternatively, you may find » the latest php.ini from Git helpful too.

Example #2 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 add a note

User Contributed Notes 4 notes

up
1
Nacho Esviza - ignacio at esviza dot com
24 days ago
This solution works for me when I needed to force two diferent versions of PHP on a Windows Server 2012 r2 & IIS:

For one application, map *.php extension to a CgiModule adding the "-c" option to the executable path, like this: "C:\php53\php-cgi.exe -c C:\php53\php.ini"

For the other application, map *.php extension to a CgiModule adding the "-c" option to the executable path, like this: "C:\php54\php-cgi.exe -c C:\php54\php.ini"

I think that way is the cleanest, because there is no need to work with PATH variable or Registry or Windows directory.

Note: for some reason, this didn't work on FastCGI module, related to the way that IIS set the executable tab not allowing command line options.
up
-1
pajoye at php dot net
1 month ago
Also a nice feature is the ability to use PHP's contants:
For example:
extension_dir=""PHP_MAJOR_VERSION"."PHP_MINOR_VERSION"/ext"
up
-22
emil at ncube dot ca
10 months ago
Note that the CLI version of PHP does not appear to take into account any php.ini configuration file. As such, something like a max_execution_time limit setting you may think is being applied is actually not being used, and instead defaulting to 0 (which is unlimited).
up
-36
Greg Robson
1 year ago
If you are on Windows and the

php --ini

command is showing the path you do not want, check the PATH environment variable.

The command line was looking for php.ini in the folder where it found php.exe. In my case this meant it was looking in
c:\Program Files (x86)\php\5.2.6
and not
c:\PHP\5.4.7

Might easily be overlooked when adding new versions to your computer.
To Top