User Specific Php.ini When php is ran as a module?

I have a php setting that can only be changed in the ini file. I can't change this setting in the global php.ini due to conflicts, so I'll need to have this user specific. Can this be done if php is ran as a module? Or must I change php run as a cgi?

Seems like the best answer is "not really", but you can sneak around changing some parameters using tricks below.


Solution 1:

I'm not aware of any way to specify a separate php.ini when using PHP as an Apache module, only when using PHP as a CGI. That said any of the configuration options in the php.ini can be changed in the .htaccess file as shown at http://php.net/configuration.changes so long as you have AllowOverride set in the Apache config set to Options or All.

I've done this on many of my sites to change common PHP configurations. I would assume that you're not needing to change every setting so the number should be easily managed by adding the options to your .htaccess file within the directory you need the changes in.

The following is one I use on a couple sites to change the include_path as well as set the auto_prepend_file and auto_append_file settings. For boolean flag items just use php_flag instead of php_value.

<IfModule mod_php5.c>
    php_value auto_prepend_file 'header.inc.php'
    php_value auto_append_file 'footer.inc.php'
    php_value include_path '/path/to/private/includes:/usr/share/pear'
</IfModule>

Solution 2:

I overrode the handler for php for a php cgi wrapper and was able to specify a php.ini file

To do this: create a htaccess file in the folder you wish to modify with something like this:

Action php5-cgi /cgi-bin/php5-cgi.cgi
AddHandler php5-cgi .php

Then create a file 'php5-cgi.cgi' with something like this:

#!/bin/sh
exec /usr/bin/php-cgi "$@" -c "/home/user/php.ini"

Set Permissions on this file to execute as the "user". Then run a test file with phpinfo(1); to see if you have your ini file loaded.

Thanks for everyones help!!