[ 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
章 9. 运行时配置
配置文件
配置文件(PHP 3 中是 php3.ini,自 PHP 4 起是 php.ini)在 PHP 启动时被读取。对于服务器模块版本的 PHP,仅在 web 服务器启动时读取一次。对于 CGI 和 CLI 版本,每次调用都会读取。
php.ini 的搜索路径如下(按顺序):
SAPI 模块所指定的位置(Apache 2 中的 PHPIniDir 指令,CGI 和 CLI 中的 -c 命令行选项,NSAPI 中的 php_ini 参数,THTTPD 中的 PHP_INI_PATH 环境变量)
HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath(Windows 注册表位置)
PHPRC 环境变量
当前工作目录(对于 CLI)
web 服务器目录(对于 SAPI 模块)或 PHP 所在目录(Windows 下其它情况)
Windows 目录(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() 来测定。
注: Apache web 服务器在启动时会把目录转到根目录,这将导致 PHP 尝试在根目录下读取 php.ini,如果存在的话。
由扩展库处理的 php.ini 指令,其文档分别在各扩展库的页面。内核配置选项见附录。不过也许不是所有的 PHP 指令都在手册中有文档说明。要得到自己的 PHP 版本中的配置指令完整列表,请阅读 php.ini 文件,其中都有注释。此外,也许从 CVS 得到的最新版 php.ini 也有帮助。
自 PHP 5.1.0 起,有可能在 .ini 文件内引用已存在的 .ini 变量。例如:open_basedir = ${open_basedir} ":/new/dir"。
运行时配置
07-Jan-2007 10:16
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.
11-Apr-2006 03:50
You can use also use the predefined PHP_SAPI constant instead of php_sapi_name().
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
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!
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.
