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

search for in the

Dil Başvuru Kılavuzu> <Yapılandırma ayarlarının yeri
Last updated: Fri, 27 Nov 2009

view this page in

Yapılandırma ayarlarının değiştirilmesi

PHP'nin bir Apache modülü olarak çalıştırılması

PHP'yi bir Apache modülü olarak kullanırken, yapılandırma ayarlarını Apache yapılandırma dosyalarındaki (httpd.conf ve .htaccess dosyaları) yönergeleri kullanarak da değiştirebilirsiniz. Bunu yapabilmek için Apache yapılandırmasında "AllowOverride Options" veya "AllowOverride All" olması gerekir.

PHP yapılandırmasını Apache yapılandırma dosyaları içinden değiştirmenize imkan veren çeşitli Apache yönergeleri vardır. PHP_INI_ALL, PHP_INI_PERDIR veya PHP_INI_SYSTEM olarak belirtilebilen yönergeleri eklerdeki php.ini yönergelerinin listesi sayfasında bulabilirsiniz.

php_value isim değer

Belirtilen değeri ismi belirtilen yönergeye atar. Sadece PHP_INI_ALL ve PHP_INI_PERDIR türü yönergeler için kullanılabilir. Önceki atanan değeri silmek için değer olarak none kullanın.

Bilginize: Mantıksal değer atamak için php_value yönergesini değil, php_flag (aşağıya bakınız) yönergesini kullanmalısınız.

php_flag isim on|off

Bir mantıksal yapılandırma yönergesi atamak için kullanılır. Sadece PHP_INI_ALL ve PHP_INI_PERDIR türü yönergeler için kullanılabilir.

php_admin_value isim değer

İsmi belirtilen yönergeye belirtilen değeri atar. .htaccess dosyalarında kullanılamaz. Bu yönerge ile atanan hiçbir yönerge türü ini_set() veya .htaccess tarafından geçersiz kılınamaz. Önceki atanan değeri silmek için değer olarak none kullanın.

php_admin_flag isim on|off

Bir mantıksal yapılandırma yönergesi atamak için kullanılır. .htaccess dosyalarında kullanılamaz. Bu yönerge ile atanan hiçbir yönerge türü .htaccess tarafından geçersiz kılınamaz.

Örnek 1 - Apache yapılandırma örneği

<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>

Dikkat

PHP sabitleri PHP dışında mevcut değildir. Örneğin, httpd.conf dosyasında error_reporting yönergesine E_ALL veya E_NOTICE PHP sabitlerini atayamazsınız. Bunu yaparsanız daima 0 olarak değerlendirileceklerdir. Sabitleri kullanmak yerine bunların bit maskelerini kullanın. Bu sabitler php.ini içinde kullanılabilir.

PHP yapılandırmasının Windows kayıt defteri üzerinden değiştirilmesi

PHP, Windows üzerinde çalışırken, yapılandırma değerleri Windows kayıt defteri kullanılarak her dizin için ayrı ayrı değiştirilebilir. Yapılandırma değerleri defterde HKLM\SOFTWARE\PHP\Per Directory Values anahtarının dizin isimlerine karşılık gelen alt anahtarlarında saklanır. Örneğin, c:\inetpub\wwwroot dizini için yapılandırma değerleri HKLM\SOFTWARE\PHP\Per Directory Values\c\inetpub\wwwroot anahtarında saklanır. Dizin ile ilgili ayarlar, dizin içinde ve alt dizinlerde çalıştırılan her betik için geçerli olur. Anahtar altındaki değerler PHP yapılandırma yönergelerinin isimlerini ve dizge değerlerini içermelidir. Değerlerde bulunan PHP sabitleri çözümlenmez. Sadece, PHP_INI_USER türü değişebilir yapılandırma değerleri bu yolla atanabilir, PHP_INI_PERDIR değerleri atanamaz.

Diğer PHP arayüzleri

PHP'yi nasıl çalıştırdığınızdan bağımsız olarak, belli değerleri betiğinizin çalışması sırasında ini_set() işlevi sayesinde değiştirebilirsiniz. Bu konuda daha ayrıntılı bilgi için ini_set() sayfasına bakınız.

Sistem yapılandırmanızla ilgili ayarlar ve mevcut değerleri ilginizi çekiyorsa phpinfo() işlevini çalıştırabilir ve elde ettiğiniz sayfayı inceleyebilirsiniz. Ayrıca, yapılandırma yönergelerinin her birine çalışma anında ini_get() veya get_cfg_var() işlevini kullanarak erişebilirsiniz.



Dil Başvuru Kılavuzu> <Yapılandırma ayarlarının yeri
Last updated: Fri, 27 Nov 2009
 
add a note add a note User Contributed Notes
Yapılandırma ayarlarının değiştirilmesi
self at pabloviquez dot com
15-Jun-2009 01:07
Note that, changing the PHP configuration via the windows registry will set the new values using php_admin_value. This makes that you cannot override them on runtime.

So for example, if you set the include_path on the windows registry and then you call the set_include_path function in your application, it will return false and won't change the include_path.
cawoodm at gmail dot com
04-May-2009 02:41
With IIS it can become confusing that changes to php.ini are ineffective. It seems it is necessary to restart the application pool for the changes to be seen. It would be great if this was not necessary - I am sure I have worked with systems where php.ini changes were immediately effectvie.
ravi at syntric dot net
09-Mar-2009 06:52
Just a quick note regarding per-directory php settings. A number of flags can be set custom to a particular app's requirement based on one of two methods describe her http://www.cognitivecombine.com/?p=207

I particularly stumbled upon this to turn off register_globals. Drupal, for e.g., required this to be off but I knew of numerous php apps that had code which relied on these globals. The .htaccess method described in the above URL worked for my case.
hyponiq at gmail dot com
09-Feb-2009 05:11
Running PHP under Apache poses a major problem when it comes to per-directory configuration settings for PHP.  In Apache virtual hosting, only a master PHP configuration file (i.e. php.ini) is parsed at run-time per PHP script.  Under IIS 6.0 or greater, you can include per-directory PHP configuration files to override or overwrite the master configuration settings.  The issue here, however, is having Apache virtual hosts override/overwrite master settings; not what IIS can do.

So, there are two possible solutions.  The first solution is described in this section and uses the Apache configuration settings php_value, php_flag, php_admin_value, and php_admin_flag.  In that, each virtual host which you'd like to have certain configuration settings changed must have these directives set (and that is for each PHP configuration setting).  This, to me, is the more viable solution, although it is time-consuming and mentally taxing.

The other possible solution is to set the PHPRC environment variable.  To my knowledge, all implementations of Apache HTTPD allow for the SetEnv directive to set the PHPRC variable per-virtual-host.  What that does is tell PHP to look in the specified location for that virtual host's configuration settings file (i.e. "C:/path/to/custom/php.ini").  The only downside to this tactic is that EVERY virtual host's custom php.ini file must contain all set parameters.  In other words, every single PHP configuration directive you have set in the master php.ini file must ALSO be set in per-virtual-host configuration settings.  Doesn't that suck?  It seems rather redundant to me (and completely defeats the purpose) that you have to include all configuration settings OVER AND OVER AGAIN.

The great thing about per-directory configuration settings (when they're implemented correctly) is that PHP already has the master settings pre-loaded and the per-directory settings (which may only ammount to one directive in difference) can be loaded per request and, thus, there is less over-head.

There really is more to this topic than that, which is why I blogged a rather lengthy and detailed article here: http://hyponiq.blogspot.com/2009/02/apache-php-multiple-phpini.html  This information is meant to help users and administrators.  I highly suggest it be read if anyone has any questions on Apache and PHP configurations.  I have included some examples that illustrate the two possible solutions, as well.  I did my best to research everything before I wrote the article.

I hope this helps!


==== 10-FEB-09: ====
I must add a little more information:

I've done some thorough testing on my PC as to the PHPRC environment variable set by the Apache directive SetEnv.  It seems to me that this variable is completely disregarded using that directive.  I tried everything and can only come to the conclusion that either A) I did something very wrong, or B) that it simply doesn't work as expected.

The former solution, however, does work magically!  So, to expand on my previous post, the only real and viable solution to this problem is to use the php_value, php_flag, php_admin_value and php_admin_flag directives in your virtual hosts configurations.

Once again, it can be very boring!  But it does work.
ludek dot stepan at gmail dot com
25-Sep-2008 11:37
Hello,

I've found this directive useful for setting per-file php.ini options. For example, when I want to have my .css styles processed as php scripts, I put this code into .htaccess to setup correct mimetype.

AddHandler php5-script .css
<FilesMatch "\.css$">
    php_value default_mimetype "text/css"
</FilesMatch>

Yours Ludek
contrees.du.reve at gmail dot com
02-Feb-2008 01: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 03: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 01: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 10: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.

Dil Başvuru Kılavuzu> <Yapılandırma ayarlarının yeri
Last updated: Fri, 27 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites