"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}
설정 파일
설정 파일(php.ini)은 PHP를 시작할 때 읽습니다. PHP 서버 모듈 버전은 웹 서버가 시작할 때 한번만 일어납니다. CGI와 CLI 버전에서는 매번 일어납니다.
php.ini는 세 위치에서 찾아집니다 (순서대로):
-
SAPI 모듈 지정 위치 (아파치 2에서 PHPIniDir 지시어, CGI와 CLI에서 -c 명령줄 옵션, NSAPI에서 php_ini 인수, THTTPD에서 PHP_INI_PATH 환경 변수)
-
PHPRC 환경 변수. PHP 5.2.0 이전에는 아래 언급한 레지스트리 키 이후에 확인했습니다.
-
PHP 5.2.0부터, 다음 레지스트리 위치가 순서대로 찾아집니다: HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z\IniFilePath, HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y\IniFilePath, HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x\IniFilePath. x, y, z는 PHP 메이저, 마이너, 릴리즈 버전을 의미합니다.
-
HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath (윈도우 레지스트리 위치)
-
현재 작업 디렉토리 (CLI 제외)
-
웹 서버 디렉토리(SAPI 모듈의 경우)나 PHP 디렉토리(윈도우 제외)
-
윈도우 디렉토리(C:\windows나 C:\winnt)(윈도우)나 --with-config-file-path 컴파일 시 옵션
php-SAPI.ini이 존재하면(SAPI는 사용하는 SAPI, 그러므로 파일명은 php-cli.ini, php-apache.ini 등), php.ini 대신 사용합니다. SAPI 이름은 php_sapi_name()으로 확인할 수 있습니다.
Note:
아파치 웹 서버는 시작할 때 디렉토리를 루트로 변경하므로, PHP는 루트 파일시스템에 php.ini가 존재할 경우 이를 읽으려고 시도합니다.
확장에 의해 다뤄지는 php.ini 지시어는 각 확장 페이지에 문서가 있습니다. 핵심 지시어 목록은 부록에 있습니다. 모든 PHP 지시어가 매뉴얼에 나와있지 않을 수 있습니다. PHP 버전에 따른 완전한 지시어 목록은, php.ini 파일을 읽어보십시오. 또는, CVS에서 » 최신 php.ini를 찾아볼 수 있습니다.
Example #1 php.ini 예제
; 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"
PHP 5.1.0부터, .ini 파일 안에서 이미 존재하는 .ini 변수를 참조할 수 있습니다. 예: open_basedir = ${open_basedir} ":/new/dir".
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!
