Mobile app version of vmapp.org
Login or Join
Pierce454

: What does "SetEnv PHPRC" do and how is it used? 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

@Pierce454

Posted in: #Htaccess #Php

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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Pierce454

1 Comments

Sorted by latest first Latest Oldest Best

 

@Alves908

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: 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:


Troubleshoot NinjaFirewall installation problems - discusses php.ini and other config files.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme