jefftanner Posted November 27, 2007 Share Posted November 27, 2007 My configuration PHP is standard with php.ini file within /etc/php5/apache2/php.ini and a copy in /etc/php5/cli/php.ini. Now I need to have a local php.ini file used when calling a PHP script that resides within the same directory as the php.ini file. For example, my setup is as follows: /websites/site/foo/root/php.ini /websites/site/foo/root/phpinfo.php DocumentRoot is /websites/site/foo/root ServerName is foo.dd.dev If I go to directory /websites/site/foo/root/, and then call from command line php -i, it shows that it is using the local php.ini file: Configuration File (php.ini) Path => /websites/site/foo/root/php.ini However, if I call http://foo.dd.dev/phpinfo.php, it shows that this PHP script is using the default apache2 php.ini file instead of the local php.ini from where phpinfo.php is called: Configuration File (php.ini) Path => /etc/php5/apache2/php.ini Any ideas of what I am missing? Thanks Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 Ive not really looked into this but Im sure it can only be done if php is installed as cgi and not as an apache module. How is php configured to run with apache? Quote Link to comment Share on other sites More sharing options...
jefftanner Posted November 27, 2007 Author Share Posted November 27, 2007 How is php configured to run with apache? Standard install: At tail of /etc/apache2/apache2.conf: LoadModule php5_module /usr/lib/apache2/modules/libphp5.so DirectoryIndex index.php index.html AddType application/x-httpd-php .php AddType application/x-httpd-php .phtml AddType application/x-httpd-php .php3 AddType application/x-httpd-php .php4 AddType application/x-httpd-php .html AddType application/x-httpd-php-source .phps # Include the virtual host configurations: Include /etc/apache2/sites-enabled/[^.#]* Include /websites/etc/apache.d/*.conf And a local apache2 config at /websites/etc/apache2.d/foo.conf: <VirtualHost *> ServerName foo.dd.dev DocumentRoot "/websites/site/foo/root/" DirectoryIndex index.php index.html index.htm <Directory "/websites/site/foo/root/"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> At /etc/hosts: 127.0.0.1 localhost 100.10.10.10 foo.dd.dev Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 Yeah, as far as I know, local php.ini's only work when php is installed as cgi, not as a module. Sorry, but ive never used cgi, so can't really be of more assistence. Quote Link to comment Share on other sites More sharing options...
jefftanner Posted November 27, 2007 Author Share Posted November 27, 2007 How is php configured to run with apache? After Googling, I discovered PHPINIDir, but it was not documented on http://www.php.net/docs.php. When I modified local apache2 config at /websites/etc/apache2.d/foo.conf: <VirtualHost *> ServerName foo.dd.dev DocumentRoot "/websites/site/foo/root/" DirectoryIndex index.php index.html index.htm PHPINIDir "/websites/site/foo/root/" <Directory "/websites/site/foo/root/"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> And call to http://foo.dd.dev/phpinfo.php shows that it is using local php.ini file installed within DocumentRoot: Configuration File (php.ini) Path => /websites/site/foo/root/php.ini So this worked. Quote Link to comment Share on other sites More sharing options...
jefftanner Posted November 27, 2007 Author Share Posted November 27, 2007 Now I want to take it one step further, I want a PHP script to use a php.ini file within a specific sub-directory under DirectoryRoot "/websites/site/foo/root/". For example; php.ini is located within "/websites/site/foo/root/bar/". Either I would like to modify local apache2 config at /websites/etc/apache2.d/foo.conf by adding a new Directory directive specifically for "/websites/site/foo/root/bar/", but I am not sure what to add: <Directory "/websites/site/foo/root/bar/"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all {PHP INI PATH directive here???} </Directory> I tried adding php_ini_path "/websites/site/foo/root/bar/" within this Directory directive, but upon apache2 restart, it did not recognize php_ini_path and failed restart. OR I also googled and read about an environment variable PHPRC which is expected to be added a .htaccess file. Within "/websites/site/foo/root/bar", I created a .htaccess file with the following single line: SetEnv PHPRC "/websites/site/foo/root/bar/" This also did not work. When calling http://foo.dd.dev/bar/phpinfo.php, it used the php.ini file declared by PHPINIDir "/websites/site/foo/root/" and not the php.ini file declared within "/websites/site/foo/root/bar". Any suggests for finer resolution for choosing a php.ini within a sub-directory within DirectoryRoot? Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.