suphpでphp.iniの設定を上書きする

共有サーバ用cgiモードphpの設定調査続き。

suPHP_ConfigPathでphp.iniの場所を指定してあげて、ユーザはそのphp.iniを編集する。suPHPのphp.iniの設定の場合、apache dsoモジュールで.htaccessからは変更できないphp_admin_value/php_admin_flagの設定も上書きできる。

デフォルトからの変更している設定の問題

suPHP_ConfigPathをユーザに使用させると、デフォルトから変更している内容がリセットされるようだ。defaultのphp.iniとユーザが設定したphp.iniはmergeしてくれないのな。

ex:) expose の値
phpのデフォルトがexpose = Onなので、/usr/local/php/lib/php.iniをexpose = Offにする。

このとき、suPHP_ConfigPathを設定していないURLについては expose = Offになっている。が、suPHP_ConfigPathを設定したURLでは、expose = Onに戻ってしまっている。もちろんphp.iniでexpose設定を上書きはしていない。


ここにも書いてた。

  • SuPHP Considerations

(略)
NOTE: PHP does not merge the php.ini files together, so when a custom php.ini is used it must contain all
of the required directives from the main php.ini file (for example, if Zend Optimizer is required, the new php.ini must load the extension.)

あとここも。

Conclusions:

1. mod_suphp has no php.ini cascading nor php.ini merging: it will not look in parent directories and it will not merge configuration files.

まとめ

  • 設定はsuPHP_ConfigPathで指定した場所にphp.iniを書けば上書き可能
  • apache dsoモジュール使用時にhttpd.conf、htaccessでは上書き出来ない、php_admin_value、php_admin_flagな設定も上書き可能
  • サーバのphp.iniでデフォルトから変更された箇所があったとしても、その設定はmergeされない

おまけ

.htaccessphp_valueが使えないけど?っていうFAQ があった。

Can I use the php_value directives in .htaccess files with suPHP?

suPHP does not support the php_value/php_admin_value directive known by mod_php to parse configuration options to scripts for certain virtual hosts or directories.


おや?そういえばmod_suphpを使わずに、cgi版のphpを普通に使う場合はどうやってphp.iniの設定を上書きすればいいんだろう。

http://php.net/manual/ja/configuration.changes.php ここに書いてた。

  • Apache モジュールとして PHP を実行している場合
    • apachehttpd.confに書く
    • htaccessに書く (AllowOverride OptionsかAllが必要)

ということだからsuphpを使わずにphpcgiで動かしている場合は設定変更は基本無理なのか。ソースを編集して

<?php ini_set ( string $varname , string $newvalue ); ?>

とやって変更するしかない。もちろんこれもphp_admin_value, php_admin_flagのものは変更できない。