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
Wie man Konfigurationseinstellungen ändert
PHP läuft als Apachemodul
Wenn man PHP als Apachemodul verwendet, kann man die Konfigurationseinstellungen mittels Direktiven in den Apache-Konfigurationsdateien (z.B. httpd.conf) und .htaccess-Dateien ändern. Dafür benötigt man "AllowOverride Options"- oder "AllowOverride All"-Privilegien.
Es gibt verschiedene Apachedirektiven, die es erlauben, die PHP-Konfiguration aus den Apache-Konfigurationsdateien heraus zu ändern. Für eine Liste von Direktiven, die als PHP_INI_ALL, PHP_INI_PERDIR, oder PHP_INI_SYSTEM definiert sind, werfen Sie einen Blick auf den Anhang Liste von php.ini Einstellungen.
-
php_valueName Wert -
Setzt den Wert der angegebenen Direktive. Kann nur für Direktiven mit den Typen PHP_INI_ALL und PHP_INI_PERDIR verwendet werden. Um einen vorher gesetzten Wert zu löschen, verwenden Sie none als Wert.
Hinweis: Verwenden Sie
php_valuenicht, um boolesche Werte zu setzen.php_flag(siehe unten) sollte stattdessen verwendet werden. -
php_flagName on|off -
Setzt eine boolesche Konfigurationsdirektive. Kann nur für Direktiven mit den Typen PHP_INI_ALL und PHP_INI_PERDIR verwendet werden.
-
php_admin_valueName Walue -
Setzt den Wert der angegebenen Direktive. Dies kann nicht in .htaccess-Dateien verwendet werden. Jeder Direktiventyp, der mit
php_admin_valuegesetzt wird, kann nicht durch .htaccess-Direktiven oder mit ini_set() überschrieben werden. Um einen vorher gesetzten Wert zu löschen, verwenden Sie none als Wert. -
php_admin_flagName on|off -
Setzt eine boolesche Konfigurationsdirektive. Dies kann nicht in .htaccess-Dateien verwendet werden. Jeder Direktiventyp, der mit
php_admin_valuegesetzt wird, kann nicht durch .htaccess-Direktiven überschrieben werden. Used to set a boolean configuration directive.
Beispiel #1 Apache-Konfigurationsbeispiel
<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>
PHP-Konstanten existieren nicht außerhalb von PHP. So kann man z.B. in der httpd.conf nicht PHP-Konstanten wie E_ALL oder E_NOTICE verwenden, um den Wert der error_reporting-Direktive zu ändern, da diese keine Bedeutung haben und als 0 ausgewertet werden. Verwenden Sie stattdessen die zugehörigen Bitmasken-Werte direkt. Diese Konstanten können in der php.ini verwendet werden.
Die PHP-Konfiguration mit der Windows Registry ändern
Wenn Sie PHP unter Windows einsetzen, können Sie die Konfigurationseinstellungen für jedes einzelne Verzeichnis mit der Windows-Registry anpassen. Die Werte der Konfiguration werden unterhalb des Registrierungsschlüssels HKLM\SOFTWARE\PHP\Per Directory Values in den zum Verzeichnisnamen passenden Unterschlüssel gespeichert.Zum Beispiel würden Werte für das Verzeichnis c:\inetpub\wwwroot im Registrierungsschlüssel HKLM\SOFTWARE\PHP\Per Directory Values\c\inetpub\wwwroot gespeichert werden. Die Einstellungen für dieses Verzeichnis wären für alle Skripte aktiv, die in diesem Verzeichnis oder einem seiner Unterverzeichnisse laufen. Die Werte in diesem Schlüssel sollten den Namen eine PHP- Konfigurationsdirektive und einen Zeichenkettenwert haben. Konstenten in den Werten werden nicht ausgewertet. Es können jedoch nur Werte, die in PHP_INI_USER änderbar sind, auf diese Weise gesetzt werden, nicht als PHP_INI_PERDIR deklarierte Werte.
Andere Zugänge zu PHP
Egal wie Sie PHP betreiben, Sie können bestimmte Werte zur Laufzeit Ihrer Skripte mittels ini_set() setzen. Werfen Sie dazu einen Blick auf die Dokumentation von ini_set().
Wenn Sie an einer kompletten Liste von Konfigurationseinstellungen Ihres Systems inklusive deren aktuellen Werten interessiert sind, können Sie die Funktion phpinfo() ausführen und die daraus resultierende Seite betrachten. Sie können auf die Werte einzelner Konfigurationsdirektiven zur Laufzeit mittels ini_get() oder get_cfg_var() zugreifen.
Wie man Konfigurationseinstellungen ändert
25-Sep-2008 11:37
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...
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
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.
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.
