Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

5 Answers 5

up vote 2 down vote accepted

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>
share|improve this answer
    
This is good, but the value I need to change is a php.ini only –  SeanDowney Jul 10 '09 at 17:29

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!!

share|improve this answer

All details are here : http://php.net/configuration.changes

share|improve this answer
    
That is helpful for changing php.ini settings, but it doesn't say if one would be allowed to change the ini file itself. I'm trying to change a setting that is php.ini only –  SeanDowney Jul 9 '09 at 22:40
    
What is the setting you want to change ? –  radius Jul 9 '09 at 22:48
    
Well really what I'm trying to do is use two different 'zend_extension' settings which conflict with each other (xdebug & zend optimizer). I would like to use the xdebug globally and only the zend optimizer in the account that requires it –  SeanDowney Jul 9 '09 at 23:04
    
Ok, I see, you can run php as cgi but it will be slow. I would suggest to start 2 instance of apache (eg. one running on port 8080 and the other on 8081) each one with the php settings you want. Then use another apache (or any other software than can do reverso proxy) instance on port 80 acting as a reverse proxy to both apache. Of course this is a less easy things to setup. –  radius Jul 9 '09 at 23:13
    
Well, that sounds crazy, but i'll look into that. Since you know your stuff, is is possible to reassociate php files with a different handler which runs a could be a cgi version of php? I was reading this online but didn't really understand if it would even apply. –  SeanDowney Jul 10 '09 at 0:32

Basically, no.

From the PHP manual:

The configuration file (php.ini) is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the CGI and CLI version, it happens on every invocation.

share|improve this answer

You may use Apache "php_admin_value" per vhost/user.

IIRC, you may redefine every php.ini value using this command

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.