dismiss Step into the future! Click here to switch to the beta php.net site
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

.user.ini files> <Runtime Configuration
[edit] Last updated: Fri, 28 Jun 2013

view this page in

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().

Note:

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.

Note:

Environment variables can be used in php.ini

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 #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".



.user.ini files> <Runtime Configuration
[edit] Last updated: Fri, 28 Jun 2013
 
add a note add a note User Contributed Notes The configuration file - [3 notes]
up
-2
Hayley Watson
3 years ago
"Since PHP 5.1.0, it is possible to refer to existing .ini variables from within .ini files."

If you have several configurations that you switch between (say development/testing/staging), or there is some other reason why several settings scattered through the .ini file might need to be changed all together on occasion, then combining this with a custom block can bring all the bits that need changing into one place:

[Customization]
custom.mode = "development"
custom.display_errors = "on"
custom.error_reporting = 30719

[PHP]
;;;;;;;;;;;;;;;;;;;
; About php.ini   ;
....

And then refer to these variables in the rest of the file:

custom.session.save_path = "/tmp/"${custom.mode}

Bringing all the changes into one location in the file is often of immense benefit.

---

Unfortunately, variable names cannot (yet) be nested. Otherwise one could have one .ini file with several customisation blocks, and a single variable to choose which set of variables to use:

[Customization]
custom.mode = "development"

[Customization Development]
custom.development.display_errors = on

[Customization Production]
custom.development.display_errors = off

...

display_errors = ${custom.${custom.mode}.display_errors}
up
0
Greg Robson
28 days 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.
up
-2
prjorgen at gmail dot com
4 years ago
Something to note which is not well documented is that when you are specifying the path, it is JUST the path that is needed - not the path and filename. In the registry locations, you need to just put the folder path (e.g. C:\PHP\) and not the full path to the INI file (e.g. C:\PHP\php.ini). This will particularly save you some headaches if you are trying to run multiple versions of PHP on one server!

 
show source | credits | stats | sitemap | contact | advertising | mirror sites