Runtime Configuration

Содержание

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 version, it happens on every invocation.

php.ini is searched 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 following registry locations are searched in order: HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z\IniFilePath, HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y\IniFilePath and HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x\IniFilePath, where x, y and z mean the PHP major, minor and release versions.

  • HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath (Windows Registry location)

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

Замечание: 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.

The php.ini directives handled by extensions are documented respectively on the pages of the extensions themselves. The list of the core directives is available in the appendix. Probably not all PHP directives are documented in the manual though. For a complete list of directives available in your PHP version, please read your well commented php.ini file. Alternatively, you may find the » the latest php.ini from CVS helpful too.

Пример #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".

Коментарии

Автор:
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.
2004-05-26 07:33:08
http://php5.kiev.ua/manual/ru/configuration.html
(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!
2005-05-26 15:47:42
http://php5.kiev.ua/manual/ru/configuration.html
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
2006-03-13 07:38:37
http://php5.kiev.ua/manual/ru/configuration.html
Автор:
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.
2006-11-18 06:21:24
http://php5.kiev.ua/manual/ru/configuration.html
[ 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
2007-01-08 00:16:32
http://php5.kiev.ua/manual/ru/configuration.html
Run php 4 and php 5.2.x on the same machine with IIS 6.0 as ISAPI.

1. Extract the ZIP packages of both php 4 & php 5 (not the Windows Installer) to c:\php4 & c:\php5 respectively

2. Setup the corresponding php.ini files in c:\php4 and c:\php5

3. Add the Web Service Extensions for php4 and php5. For php4 use c:\php4\sapi\php4isapi.dll, php5 use c:\php5\php5isapi.dll

4. Add the following registry keys:

HKEY_LOCAL_MACHINE\SOFTWARE\PHP\5\IniFilePath -> c:\php5

HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath -> c:\php4

5. Add c:\php4 to the PATH environment variable.

6. Associate each web site in IIS with the corresponding php version.

7. Reboot

Note: That should work, test with phpinfo() in each site. You may need to refer to the php documentation if we missed any other settings.
2007-03-29 15:19:36
http://php5.kiev.ua/manual/ru/configuration.html
In order to get PHP 5.2 stable running on Windows Server 2003 x64 (IIS 6.0), I discovered three things (in addition to the other comments above):

* Some PHP web applications make use of the SCRIPT_NAME server variable which is not available under CGI. You have to use php5isapi.dll, which is a 32 bit dll, so you have to run IIS in 32 bit mode. Confer http://support.microsoft.com/kb/894435. This applies to all ISAPI extensions and not just ASP.NET.

* It appears you must leave the doc_root entry in php.ini blank. At least, that is what finally made my installation work. (Note that others have suggested to set it to e.g. C:\inetpub\wwwroot or equivalent. That won't work if your server hosts more than one domain, each placed in a separate directory.)

* If you are e.g. using MySQL you will have to edit php.ini. In order for it to be found, you must set the PHPRC system environment variable or the registry entry. Note that if you edit the registry using regedit.exe, the PHP key should be placed under the [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node] key. This happens automatically if you set it using a 32 bit legacy application.
2007-04-01 08:07:07
http://php5.kiev.ua/manual/ru/configuration.html
About Apache 2.0 module:

For whatever reason, the Windows installer for PHP/5.2.3 tries to set the PHPIniDir directive using "\\" as directory separator:

PHPIniDir "C:\\Archivos de programa\\PHP\\"

It didn't work for me until I edited httpd.conf and replaced it with "/":

PHPIniDir "C:/Archivos de programa/PHP/"
2007-06-16 08:01:33
http://php5.kiev.ua/manual/ru/configuration.html
Be sure to use double quotes in the php.ini file. For instance:

(lines broken for readability)

this will work:
# xdebug debugging
zend_extension="/usr/local/php5/lib/php/extensions
/no-debug-non-zts-20060613/xdebug.so"

this won't:
# xdebug debugging
zend_extension='/usr/local/php5/lib/php/extensions
/no-debug-non-zts-20060613/xdebug.so'

You'll get this error: 
Failed loading '/usr/local/php5/lib/php/extensions/
no-debug-non-zts-20060613/xdebug.so':  (null)

So... double quotes are the way! I know this is obvious, but it's a good thing to remember for the php.ini file.
2007-06-25 20:01:45
http://php5.kiev.ua/manual/ru/configuration.html
Автор:
Hello,

Having tried EVERYTHING on every php / mysql site to get php5.2.5 to talk to mysql server 5.0 (including all php.ini settings, all dlls, and many more ...)

Please try this: set Apache2.2 service Startup Type to MANUAL.  If not, it does not see to reload php.ini, no matter how many times you stop and start.

After 2 days, I finally see mysql info for <?php phpinfo(); ?>

Hope this helps!!
DK
2008-02-06 16:03:50
http://php5.kiev.ua/manual/ru/configuration.html
w2k, apache 1.3.29, php 5.2.6: c:\php\php.ini was not found until the environment variable PHPRC was set to "c:\php", even though php was used as a module, not CGI.

just adding c:\php to the path was not adequate.

phpinfo() still shows "Configuration File (php.ini) Path" to be C:\WINNT, but "Loaded Configuration File" now correctly displays "C:\php\php.ini".

initially the problem appeared to be simply that the mysql extension was not loading; in fact, the problem was more fundamental (php.ini not found) but because php will still work with defaults, this was not obvious.
2008-07-27 13:33:09
http://php5.kiev.ua/manual/ru/configuration.html
PHP 5.2.6 & Apache 2.2
----------------------
If you tried everything above and you server is not executing php script, look in php.ini at value:

short_open_tag = Off 
;it does not recognise '<?', only '<? php' or '<script>'

Some editors come with '
<?' as default, like mine did. After two days I finally found out...
2008-10-24 01:10:00
http://php5.kiev.ua/manual/ru/configuration.html
For windows with limited file permission (Windows XP)

1. Install Apache in your folder profile "C:\Documents and Settings\your_profile"

2. Add the following directives to you httpd.conf
PHPINIDir "C:\Documents and Settings\your_profile\php"

LoadModule php5_module "C:\Documents and Settings\your_profile\php\php5apache2_2.dll"

AddType application/x-httpd-php .php

3. Edit the following directive to you php.ini
extension_dir = "C:\Documents and Settings\your_profile\php\ext"

4. Move the file libmysql.dll from C:\Documents and Settings\your_profile\php\ to C:\Documents and Settings\your_profile\php\ext\

5. Restart httpd using command line
2010-11-30 21:18:08
http://php5.kiev.ua/manual/ru/configuration.html
Автор:
To run separate apache and php processes on centos (at least) without
having to compile and install separate versions for every instance
this should work:

Install apache and php with yum.

This will give you (for the first instance):

/etc/httpd/*, /etc/sysconfig/httpd, /etc/init.d/httpd, /etc/php.ini
and /etc/php.d/*.

Copy all this stuff to:
/etc/httpd2/*, /etc/sysconfig/httpd2, /etc/init.d/httpd2,  /etc/php2.ini
and /etc/php2.d/*.

Then:

Edit the apache config files in /etc/httpd2/* to reflect the new
ports you want to have this apache listen on (don't forget ssl.conf
under conf.d) and any other differing settings, like log file
destinations and virtualhosts.

Edit the php2.ini for any specific settings you want the other php 
instance to have.

To have a completely separate php in this new apache instance with its own
modules included, edit /etc/sysconfig/httpd2 and add the following:

PHPRC=/etc/php2.ini
export PHPRC
PHP_INI_SCAN_DIR=/etc/php2.d
export PHP_INI_SCAN_DIR

This will set the environment variables for the second apache/php
instance before it is started.

Then edit /etc/init.d/httpd2 and change all references to httpd
(like lockfile, pidfile and sysconfig) to httpd2. Don't touch the
executable name, though :)

And change this:

LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS

to this:

LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd -f /etc/httpd2/conf/httpd.conf $OPTIONS

.. so this apache can find its own configuration file.

Then, if necessary 'chkconfig --add /etc/init.d/httpd2' to have it
in startup and you should have two apache instances with two separate
php modules with their own dedicated settings.
2013-09-17 13:30:44
http://php5.kiev.ua/manual/ru/configuration.html

    Поддержать сайт на родительском проекте КГБ