NOTE: Since PHP 5.1.0, it is possible to refer to existing .ini variables from within .ini files. Example:
- Code: Select all
open_basedir = ${open_basedir} ":/new/dir"
From: The php.ini file
PHP looks for custom php.ini: (in order) (In order for PHP to read it, it must be named 'php.ini')
- In the Current working directory (CWD)
- Code: Select all
Place your php.ini in the same directory as the php executable.
If php executable is here: /home/user1/htdocs/cgi-bin/
then place your php.ini file here: /home/user1/htdocs/cgi-bin/php.ini
- In the path specified by the environment variable PHPRC
(SetEnv PHPRC only works when using PHP as CGI, not when using php as an Apache Module)- If you can use SetEnv in .htaccess files
in root .htaccess specify the path to the directory containing php.ini, not the direct path- Code: Select all
SetEnv PHPRC /home/user1
- If you can't use setenv and you are using a wrapper shell script
place this in the wrapper shell script- Code: Select all
export PHPRC=/home/user1
- If you can use SetEnv in .htaccess files
- In the path that was defined at compile time with --with-config-file-path
- The path in which the php.ini file is looked for can be overridden using the -c argument in command line mode. (cgi)
- Code: Select all
/home/user1/htdocs/cgi-bin/php.cgi -c /home/user1/php.ini
With this option one can either specify a directory where to look for php.ini or you can specify a custom INI file directly (which does not need to be named php.ini), e.g.:- Code: Select all
$ php -c /custom/directory/ my_script.php
$ php -c /custom/directory/custom-file.ini my_script.php
- Under Windows, the compile-time path is the Windows directory.
- Code: Select all
Place php.ini in one of the directories, C:\windows or C:\winnt
- The path in which the php.ini file is looked for can be overridden using the -c argument in command line mode. (cgi)
From: PHP Runtime Configuration
php.ini is searched for by php 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
- PHPIniDir directive in Apache 2
- The PHPRC environment variable. (Before PHP 5.2.0 this was checked after the registry key mentioned below.)
- HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath (Windows Registry location)
- Current working directory (for CLI)
- The web server's directory (for SAPI modules)
- Directory of PHP (If in Windows)
- Windows directory (C:\windows or C:\winnt)
- --with-config-file-path compile time option
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.
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(). You can use also use the predefined PHP_SAPI constant instead of php_sapi_name()
When php is run as CGI
Place your php.ini file in the same directory of your cgi version of php, in most cases you should have it in /cgi-bin/ on Dreamhost it is called php5.cgi.
root htaccess might look something like this
- Code: Select all
AddHandler php-cgi .php
Action php-cgi /cgi-bin/php5.cgi
When cgi'd php is run with wrapper (for FastCGI)
You will have a shell wrapper script like this
php-wrap.fcgi
- Code: Select all
#!/bin/sh
export PHP_FCGI_CHILDREN=3
exec /x.com/cgi-bin/php.cgi -c /abs/path/to/php.ini
cgi.fix_pathinfo boolean
Provides real PATH_INFO/PATH_TRANSLATED support for CGI. PHP's previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting this to 1 will cause PHP CGI to fix it's paths to conform to the spec. A setting of zero causes PHP to behave as before. Default is zero. You should fix your scripts to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
cgi.force_redirect boolean
gi.force_redirect is necessary to provide security running PHP as a CGI under most web servers. Left undefined, PHP turns this on by default. You can turn it off at your own risk.
cgi.redirect_status_env string
If cgi.force_redirect is turned on, and you are not running under Apache or Netscape (iPlanet) web servers, you may need to set an environment variable name that PHP will look for to know it is OK to continue execution.
Note: Setting this variable may cause security issues, know what you are doing first.
fastcgi.impersonate string
FastCGI under IIS (on WINNT based OS) supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under. mod_fastcgi under Apache does not currently support this feature (03/17/2002) Set to 1 if running under IIS. Default is zero.
If your server is running Windows