PHP: Configuration - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links | my php.net 
search for in the  
<Problems?How to change configuration settings>
view the version of this page
Last updated: Wed, 29 Jan 2003

장 4. Configuration

The configuration file

The configuration file (called php3.ini in PHP 3.0, and simply php.ini as of PHP 4.0) 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.

The default location of php.ini is a compile time option (see the FAQ entry), but can be changed for the CGI and CLI version with the -c command line switch, see the chapter about using PHP from the command line. You can also use the environment variable PHPRC for an additional path to search for a php.ini file.

Not every PHP directive is documented below. For a list of all directives, please read your well commented php.ini file. You may want to view the latest from CVS.

참고: The default value for the PHP directive register_globals changed from on to off in PHP .

예 4-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
magic_quotes_gpc = 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"



User Contributed Notes
Configuration
add a note add a note
spambucketremovethis at usa dot net
11-Feb-2001 07:40

Finally figured this out: if you are using server side includes (SSI) with Apache, and have added a line

AddHandler server-parsed .html

in your httpd.conf file so that .html files can use SSI, this setting will prevent

AddType application/x-httpd-php .php .html

from working (.php will work, but .html won't). From what I've figured out so far, you need to dump SSI support for .html files if you want to get PHP to work with .html files.  No loss since PHP duplicates the functionality, I think. (Of course be aware that enabling PHP parsing of .html files will make performance suffer somewhat, especially if most of your files do not need PHP.)

Another thing I've learned is that even with all this talk of the php.ini files, they are not even required unless you need to make adjustments. If there is no php.ini file, the defaults will be used.

michael at dynamine dot net dot remove dot this
29-Nov-2001 05:08

If you want to specify the location of your php.ini file at runtime, set the environment variable PHPRC equal to the directory in which php.ini is located.  Note that the filename php.ini cannot be changed; just the directory in which it's stored.
chris-php at bolt dot cx
16-May-2002 04:35

Unlike Apache logs, the error_log is opened after the server is started, so it must have the permissions the server runs as (usually nobody)
php dot net at odi dot ch
14-Jun-2002 10:17

[[[Editors note:
magic_quotes_gpc being on does save a lot of support questions. Everyone is free to read the documentation (php.ini and manual) and plan accordingly.  In fact, PHP comes with two php.ini files, one is called  php.ini-recommended and it has magic_quotes_gpc off.  See also: stripslashes(), get_magic_quotes_gpc(), and .htaccess.
]]]

Beware, magic_quotes_gpc  is evil !

The option may look very tempting at the first glance. However there are some caveats:

 1. Most parameters do not go to a database.
In a web application most form field are used internally without the need to store them in a database. Magic quotes  cause troubles in these cases.
Moreover the data passed to the application is not the data entered by the user if it was processed by magic quotes. This is undesireable.

 2. Impedes code reuse.
If you feed data from either form parameters or internal data sources into the same function then your function must know if the data was processed by magic quotes or not.

 3. Bad surprises at deployment time and code portability.
If you do not carefully check if this parameter is set on your development and production system you can run into troubles. Especially if you can not change the settings on one system (because the hoster does not let you).

 4. Behaviour can not be controlled at script runtime.
The ini_set does not help in this case even though the parameter can be modified at runtime the behaviour does not change. Consequently you are bound to the php.ini settings (which may be not under your control).

I therefore request that this option be removed from future versions of PHP and the default behaviour should be FALSE.

netdelay at linuxbr dot com dot br
07-Aug-2002 08:32

You can configure this values for independent VirtualHosts.
Just put at your httpd.conf <VirtualHost> section the flag
php_admin_value <variable_name> <value>

Example:

<VirtualHost 127.0.0.1>
  DocumentRoot /path/to/file
  ServerName your.website.name
  php_admin_value auto_prepend_file /path/to/file/lib/config.inc.php
</VirtualHost>

And now the file config.inc.php will be automatically loaded before the main file, but only for this Virtual Host

13-Aug-2002 12:38
Should be trivial but was not so trivial for me :)
 error_log = filename
 error_log =/path/filename

Make sure php user (usually nobody) have privileges to write to filename or /path/filename. Or you will get nor error logged.

dangNOSPAM at planetmirror dot NOSPAM dot com
26-Mar-2003 05:29

Okay this one took a while. I was having issues changing the default
upload_max_filesize value.

phpinfo(); told me where my php.ini file was. So I looked there and
... no such file.

so I created one, and set post_max_size and upload_max_filesize.

I restarted apache, and ... no luck.

So the solution, I found, was to specify these things in the httpd.conf
file for Apache, as php_values:

php_value upload_max_filesize 10000000
php_value post_max_size 10000000

Hope this helps others in the same situation.

Shurik dot from OZ
01-May-2003 02:19

Users of Linux who installed PHP binaries for Linux may not have MySQL libraries support by default. This causes errors when calling mysql standard functions from your php code.
To enable MySQL support in Linux go to your RPM (e.g. in KDE  Configuration->Packaging->install software) and then look for the "php-mysql-x.x.x.x" package (e.g. search all packages on 'mysql'). Install missing package - the problem solved!

allen AT brooker DOT G(ee)B(ee) DOT net
08-May-2003 11:37

In reference to the post by php dot net at odi dot ch

Yes magic_quotes is slightly evil, but we have to live with it, and to be honest its not a problem, I now have a file which runs these sorts of chekcs thats included at the beginning of the script. My code for magic quotes looks like this:

 // 'Turn off' magic_quotes_gpc
 if (get_magic_quotes_gpc ()) {
   foreach ($_POST as $key => $value) {
     $_POST[$key] = stripslashes ($value);
   }
       
 foreach ($_GET as $key => $value) {
     $_GET[$key] = stripslashes ($value);
   }

   foreach ($_COOKIE as $key => $value) {
     $_COOKIE[$key] = stripslashes ($value);
   }
}

So saying that the behavious cannot be modified at runtime is actually incorrect.

I'm even creating a new template database script which allows me to easily work around the more evil magic_quotes_runtime by writing my own database routines (the script is in fact designed for small databases and can be run either using flatfiles or MySQL).

It would make my life way easier if they removed safe mode from PHP, but it isn't going to happen. Live with it and love it :)

Allen

add a note add a note

<Problems?How to change configuration settings>
 Last updated: Wed, 29 Jan 2003
show source | credits | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: /
Last updated: Wed May 21 21:10:23 2003 CEST