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?

share|improve this question
up vote 9 down vote accepted

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().

share|improve this answer
    
Hmm... That'd work, but I don't have access to that server configuration. – Niet the Dark Absol Feb 13 '12 at 22:41
    
@Kolink If you don't have access to that, consult your host. They may have already set something up. – alex Feb 13 '12 at 22:43
    
Okay, thank you. I will. :) – Niet the Dark Absol Feb 13 '12 at 22:50

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.

share|improve this answer
    
Actually, I'm on a VDS in this case. Anyway, turns out suPHP_ConfigPath was the answer (I asked the host about it). – Niet the Dark Absol Feb 14 '12 at 1:15
    
?VDS? not an acronym that I've come across. If you mean VPS then why on earth have you configured it for suPHP?. The only logical reason for using suPHP is to enable UID based access control to maintain separation between cohosted accounts. – TerryE Feb 14 '12 at 1:45
    
Virtual Dedicated Server. To be honest, I don't care how it works as long as it works and does what I tell it to do. – Niet the Dark Absol Feb 14 '12 at 2:21
    
As long as you understand that your users will see a (slight) performance hit, and your VM will max out at ~5 URI script requests per sec. – TerryE Feb 14 '12 at 10:31
1  
It's only for dev purposes. Before going live it'll get moved to a properly dedicated system ;) – Niet the Dark Absol Feb 14 '12 at 15:58

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.

share|improve this answer
1  
You missed to quote a very important part: Since PHP 5.3.0, PHP includes support for configuration INI files on a per-directory basis. These files are processed only by the CGI/FastCGI SAPI – lucaferrario Aug 31 '17 at 9:28

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.