我想知道是否可以在目录级别使用 php.ini 文件?具体来说,我有一个域指向子目录中的虚拟文档根目录,并且想要覆盖之前在物理根目录中的 php.ini 文件中定义的一些 php.ini 值。
这是否可以简单地通过在子目录中的新 php.ini 中重新定义这些值?我试图避免在.htaccess
文件中定义这些。
In general no, but in special (CGI/FastCGI) yes: http://php.net/configuration.file.per-user
Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on a per-directory basis. These files are processed only by the CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are using Apache, use .htaccess files for the same effect.
In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the document root, only its directory is scanned.
You can only set a limited subset of the ini-options in the user-ini-file. If you are hosting several independent sites on one server, you should consider FastCGI anyway, to keep them separated. With php5-fpm
it's very easy to setup many pools of workers.