问题
My development environment is shared with other developers of my startup and is setup on Rackspace. The php.ini file is located in /etc/
folder, and I believe this is a centralized location from where every other developer's dev environment setting is being configured from. I want to customize this php.ini
file specifically for myself rather than having to do it in the /etc
/ location.
Specifically I am setting up XDEBUG in my environment, some other developers don't want it, so I don't want to bug em :)
To do so, I scanned the Internet on how to override the php.ini file specifically for a directory, and found this page on stackoverflow
And following that, I simply copy pasted the php.ini file within my htdocs folder and then simply echoed out phpinfo()
(I echoed this in one of my Controllers, (using Zend)). The index.php file is within the htdocs folder.
When I look @ "Loaded Configuration File", it still reads
/etc/
instead of ../htdocs/
Anybody know what's up?
回答1:
In general, it isn't possible to load php.ini
on a per directory basis, but in some special cases (CGI/FastCGI), it is: see documentation for Per-user configuration
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.
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.
Note that only set a limited subset of the ini-options in the user-ini-file. As you said you don't have control on the server, the possible work-arounds would be to:
- Use ini_set() to override the changes inside your script. Not all of the configuration directives can be changed using
ini_set()
though. - Use an .htaccess file in your directory to override the configurations in
php.ini
file.
(certain parts adapted from #1438393)
Hope this helps!
回答2:
I'm not sure you understood the post. The post means if you run the server and want a per domain php.ini you can run the module as a per domain so each user controls there domain php.ini however it looks like your server does not offer this so you will need to us htaccess file to overwrite the php.ini settings.
By over write this doesn't mean you can change the directory this means maybe add a module or add error reporting ect...
You can do it by using this post: How can I use xdebug to debug only one virtual host?
来源:https://stackoverflow.com/questions/17688944/overriding-php-ini-in-a-shared-development-environment