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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.