What does "SetEnv PHPRC" do and how is it used?

What does "SetEnv PHPRC" do and how is it used? - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, php, , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I have a client with some technical skills who likes to take a look at files and understand how they work.



Yesterday, we installed Ninja Firewall in their WordPress and their web host server setup needs SetEnv PHPRC to the php.ini path in the .htaccess file. I would like an explanation of SetEnv PHPRC in Plain English for my client, but my research has only come up with a little bit of this and a little bit of that and no clear explanations.


Solution :


PHPRC is a replacement for php.ini, ... The sites seem to tell how to create one.



I think that is something a bit different (regarding creating a "phprc" file - a local PHP config file - something unique to DreamHost AFAIK)?


The PHPRC (PHP Runtime Configuration) environment variable is one way to tell PHP where to find the main php.ini file. It can sometimes be used to change the location of the main php.ini file.

Reference: http://php.net/configuration.file


On some hosts, the PHPRC environment variable can also be used to set a local (per site) php.ini PHP config file. (Otherwise, trying to change the location of php.ini on a shared host will not do anything, apart from setting the environment variable.) This can also be achieved using a local .user.ini file and/or .htaccess - but this can vary from host to host.


The Apache directive SetEnv (part of mod_env) simply sets this environment variable. PHPRC is then available to any scripting language that reads these environment variables.


Why is this required for NinjaFirewall?


The NinjaFirewall docs state:



Installation... NinjaFirewall will need to add some instructions to your system files (php.ini, .htaccess). In most cases, it will be able to detect your configuration and to make those changes for you



My guess is that NinjaFirewall needs a local (php.ini in your case) config file in which to make changes. Or, less likely, needs the PHPRC env var set in order to be able find the location of the php.ini file, which can then be edited. (The specific path that is being set will tell you this... is it a path within your webspace? Or somewhere else on the file system?)


It's also stated in this WordPress.org thread, that:



The SetEnv PHPRC directive in the .htaccess is only needed when you are using a php.ini that is not recursive, i.e., that does not apply to subdirectories.



Although that doesn't seem make much sense to me? (If php.ini is not "recursive", then I don't think you would be using php.ini to begin with?)


Further reading:



Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect