0

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?

Community
  • 1
  • 1
Parijat Kalia
  • 4,929
  • 10
  • 50
  • 77

2 Answers2

5

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!

Community
  • 1
  • 1
Amal Murali
  • 75,622
  • 18
  • 128
  • 150
  • I do not think adding ini_set() will help since I am attempting to load xDebug (or will it). but the htdocs option seems interesting...will try :) – Parijat Kalia Jul 17 '13 at 00:17
  • -1 just plain wrong. php can load multiple ini files on a per directory basis. – goat Jul 17 '13 at 00:20
  • 1
    @chris, you haven't followed the conversation. Yes you may load as many php.ini files per directory and it will work fine as long as you restart apache each time. I do not have access privileges to start apache. – Parijat Kalia Jul 17 '13 at 00:28
  • @amal, so using .htaccess to override some of the php.ini settings seems to be the way to go. Does this mean when I echo phpinfo() it will read the overriden properties value from htdocs or will it still read it from php.ini ? Reason I ask is simply because I need to check if certain properties were set correctly. – Parijat Kalia Jul 17 '13 at 00:30
  • 1
    @ParijatKalia you dont need to restart apache. – goat Jul 17 '13 at 01:18
1

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?

Community
  • 1
  • 1
Liam Sorsby
  • 2,912
  • 3
  • 28
  • 51