PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Referência da Linguagem> <Configuração em tempo de execução
Last updated: Fri, 22 Aug 2008

view this page in

Como mudar as configurações

Executando PHP como módulo do Apache

Quando usar o PHP como módulo do Apache, você pode mudar as configurações usando diretivas nos arquivos de configuração do Apache (ex.: httpd.conf e .htaccess). Você precisa de privilégios "AllowOverride Options" ou "AllowOverride All" para isso.

Há vários diretivas do Apache que você pode mudar a configuração do PHP de dentro dos arquivos dos arquivos de configuração do Apache. Para uma lista de quais diretivas são PHP_INI_ALL, PHP_INI_PERDIR, or PHP_INI_SYSTEM, olhe no apêndice Lista de diretivas do arquivo php.ini.

php_value nome valor

Configura o valor da diretiva especificada. Pode ser usado apenas com diretivas do tipo PHP_INI_ALL e PHP_INI_PERDIR. Para limpar um valor configurado anteriormente, use o valor none.

Nota: Não use php_value para configurar valores booleanos. php_flag (veja abaixo) deve ser usada, ao invés.

php_flag nome on|off

Usado para configurar diretivas de configuração booleanas. Pode ser usada apenas com diretivas do tipo PHP_INI_ALL e PHP_INI_PERDIR.

php_admin_value nome valor

Configura o valor da diretiva especificada. Isso não pode ser usado em arquivos .htaccess. Qualquer tipo diretiva configurada com php_admin_value não pode ser sobrescrita por diretivas .htaccess. Para limpar um valor configurado anteriormente, use o valor none.

php_admin_flag nome on|off

Usado para configura diretiva de configuração booleana. Isso não pode ser usado em arquivos .htaccess. Qualquer tipo diretiva configurada com php_admin_flag não pode ser sobrescrita por diretivas .htaccess. Para limpar um valor configurado anteriormente, use o valor none.

Exemplo #1 Exemplo de configuração do Apache

                                <IfModule mod_php5.c>
                                    php_value include_path ".:/usr/local/lib/php"
                                    php_admin_flag safe_mode on
                                </IfModule>
                                <IfModule mod_php4.c>
                                    php_value include_path ".:/usr/local/lib/php"
                                    php_admin_flag safe_mode on
                                </IfModule>
                                

Cuidado

Constantes PHP não existem fora do PHP. Por exemplo, no arquivo httpd.conf você não pode usar constantes do PHP como E_ALL ou E_NOTICE para configurar a diretiva error_reporting, já que elas não terão significado algum e serão avaliadas como 0. Ao invés, use os valores de bitmask associados. Essas constantes podem ser usados no arquivo php.ini

Mudando configuração do PHP através do registro do Windows

Quando executar o PHP no Windows, os valores de configuração pode ser modificados para cada diretório, usando o registro do Windows. Os valores de configuração são guardados na chave de registro HKLM\SOFTWARE\PHP\Per Directory Values, nas sub-chaves correspondentes aos caminhos dos diretórios. Por exemplo, valores para o diretório c:\inetpub\wwwroot estariam guardadas na chave HKLM\SOFTWARE\PHP\Per Directory Values\c\inetpub\wwwroot. As configurações para o diretório estariam ativos para qualquer script rodando desse diretório ou qualquer subdiretório dele. Os valores na chave devem ter o nome da diretiva de configuração do PHP e um valor string. Constantes do PHP nos valores não são avaliados. Entretanto, apenas valores de configurações modificáveis no PHP_INI_USER podem ser definidos desta maneira, valores PHP_INI_PERDIR não podem.

Outras interfaces para PHP

Independente de como você execute PHP, você pode mudar certos valore durante a execução de seus scripts através ini_set(). Veja a documentação na página ini_set() para mais informações.

Se você estiver interessado na lista completa de configurações no seu sistema com o valores atuais, você pode executar a função phpinfo() , e revisar a página resultante. Você pode também acessar os valores de configurações de diretivas individuais em tempo de execução usando ini_get() ou get_cfg_var().



add a note add a note User Contributed Notes
Como mudar as configurações
contrees.du.reve at gmail dot com
02-Feb-2008 03:25
Being able to put php directives in httpd.conf and have them work on a per-directory or per-vitual host basis is just great. Now there's another aspect which might be worth being aware of:

A php.ini directive put into your apache conf file applies to php when it runs as an apache module (i.e. in a web page), but NOT when it runs as CLI (command-line interface).

Such feature that might be unwanted by an unhappy few, but I guess most will find it useful. As far as I'm concerned, I'm really happy that I can use open_basedir in my httpd.conf file, and it restricts the access of web users and sub-admins  of my domain, but it does NOT restrict my own command-line php scripts...
webmaster at htaccesselite dot com
12-Jul-2007 06:18
To change the configuration for php running as cgi those handy module commands won't work.. The work-around is being able to tell php to start with a custom php.ini file.. configured the way you want.

 With multiple custom php.ini files
-------------------------------------------
/site/ini/1/php.ini
/site/ini/2/php.ini
/site/ini/3/php.ini
--

The trick is creating a wrapper script to set the location of the php.ini file that php will use. Then it exec's the php cgi.

 shell script /cgi-bin/phpini.cgi
-------------------------------------------
#!/bin/sh
export PHPRC=/site/ini/1
exec /cgi-bin/php5.cgi
--

Now all you have to do is setup Apache to run php files through the wrapper script instead of just executing the php cgi.

 In your .htaccess or httpd.conf file
-------------------------------------------
AddHandler php-cgi .php
Action php-cgi /cgi-bin/phpini.cgi
--

So to change the configuration of php you just need to change the PHPRC variable to point to a different directory containing your customized php.ini.. You could also create multiple shell wrapper scripts and create multiple Handler's+Actions in .htaccess..

 in your .htaccess
-------------------------------------------
AddHandler php-cgi1 .php1
Action php-cgi1 /cgi-bin/phpini-1.cgi

AddHandler php-cgi2 .php2
Action php-cgi2 /cgi-bin/phpini-2.cgi

AddHandler php-cgi3 .php3
Action php-cgi3 /cgi-bin/phpini-3.cgi
--

The only caveat here is that it seems like you would have to rename the file extensions, but there are ways around that too ->
http://www.askapache.com/php/custom-phpini-tips-and-tricks.html
Woody/mC
09-Jul-2007 04:09
@ pgl: As the documentation says:

"To clear a previously set value use none as the value."

Works fine for me.
pgl at yoyo dot org
27-Jun-2007 01:59
It is not possible to unset a config option using php_value. This caused me problems with auto_prepend_file settings where I wanted to have a global file auto included, with an exception for only one site. The solution used to be to use auto_prepend_file /dev/null, but this now causes errors, so I just create and include blank.inc now instead.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites