1

I am wondering whether I can use a php.ini file at the directory level? Specifically, I have a domain pointed to a virtual document root in a sub-directory and would like to override some php.ini values previously defined in the php.ini file located in the physical root directory.

Is this possible simply by redefining these values in a new php.ini in the sub-directory? I'm trying to stay away from defining these in .htaccess file.

hakre
  • 193,403
  • 52
  • 435
  • 836
Chad Kidner
  • 11
  • 1
  • 3
  • Generally yes, but that may only apply to a subset of settings... did you try? – Grant Thomas Nov 23 '12 at 21:56
  • @GrantThomas Yes I did but it was not being loaded. I wasn't sure if I was missing a setting somewhere. – Chad Kidner Nov 24 '12 at 06:07
  • [The PHP manual explains this](http://php.net/configuration.file.per-user). It also depends on the server API you're using (SAPI), see http://php.net/php-sapi-name and http://php.net/reserved.constants#reserved.constants.core – hakre Nov 24 '12 at 11:17

1 Answers1

1

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.

Community
  • 1
  • 1
KingCrunch
  • 128,817
  • 21
  • 151
  • 173
  • Thank you for all the great information. Sounds like my configuration meets all the criteria you mention.. And it does do as you say and scans for the additional ini files but does not seem to support for a Virtual Document Root directory as when I test with a phpinfo script it shows only the server configuration php.ini and the php5.ini in my Document Root are loaded. I do see a spot that says "Additional .ini files parsed", but result given is (none). I have ended up just defining the .ini options I needed for now in a .htaccess file. Thanks again for the tips! – Chad Kidner Nov 24 '12 at 06:01