Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set path to php.ini

Tags:

php

apache

Is it possible to have just a single php.ini file, for example in the webroot (or even outside of it to prevent people accessing it via GET), and tell PHP quickly and easily where it is?

I know you can set php.ini directives in .htaccess, but is it possible to define a specific php.ini file to be used?

like image 680
Niet the Dark Absol Avatar asked Feb 13 '12 22:02

Niet the Dark Absol


3 Answers

Add this to your server configuration...

<VirtualHost 1.2.3.4:80>
PHPINIDir /path/to/new/php_ini
</VirtualHost>

Make sure to just include the path to the directory, not the entire path to the file.

Then restart Apache.

Check it worked with phpinfo().

like image 68
alex Avatar answered Sep 22 '22 21:09

alex


Have a look at .user.ini section at the php docs.

Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on a per-directory basis.

But beside the .unser.ini solution you can place an additional ini file in the "additional .ini files parsed" directory. There you can use one single ini file to overwrite all other settings. Name it with zzz at the beginning and it will be parsed at last. This is also easy for your hoster to deploy without destroying his settings.

like image 34
powtac Avatar answered Sep 22 '22 21:09

powtac


Kolink, I suspect that you are on a shared hosting service, in which case your host may be using something called suPHP. In this case -- as you describe -- the PHPINIDir directive doesn't work, in which case there is a suPHP_ConfigPath directive.

In terms of access, I have a standard mod_rewrite in my DOCROOT/.htaccess:

RewriteEngine   On
RewriteBase     /
# if a forbidden directory or file name (starting with a . or /) then raise 404 Fatal
RewriteRule (^|/)[_.] -         [F]

What this does is forbid any request for any filename or directory prefixed by . or _. I have a DOCROOT/_private where I keep this stuff for me:

suPHP_ConfigPath DOCROOT/_private

where you will need to replace DOCROOT by your local setting on your service. Look for DOCUMENT_ROOT in a phpinfo() listing.

like image 40
TerryE Avatar answered Sep 20 '22 21:09

TerryE