Jump to content

Local php.ini file ignored when calling PHP script from same directory


Recommended Posts

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

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

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.

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.