5

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.

4
  • 1
    Try googling environment variables instead of "SetEnv"?
    – user3919
    Dec 18, 2016 at 9:26
  • It's the same problem with searching for environmental variables. PHPRC is a replacement for php.ini, I don't seem to find information on why and what the difference is. The sites seem to tell how to create one. We don't need to create it, I just to explain it better. Dec 18, 2016 at 20:16
  • 1
    I have removed your request for an external resource. It would be preferable that the explanation that you are looking for gets written as an answer here. Dec 19, 2016 at 12:50
  • linux.math.tifr.res.in/linux-manual/env-howto.html is an external resource. I hate duplicating content, so I'm doing this as a comment.
    – user3919
    Dec 19, 2016 at 19:49

1 Answer 1

4

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:

3
  • I think that your answer explains a piece of information I was missing. Based on your comments, I understand thatPHPRC does not replace php.ini, it points to where the php.ini file is stored. If I am indeed understanding your explanation correctly, my simplified version is an answer my client will understand. Dec 19, 2016 at 21:08
  • Yes, it points to where php.ini is stored. A custom PHP config file just for this site I assume. I'm curious... what path is set for PHPRC? Is it pointing to somewhere within the webspace itself? Or somewhere else on the file system?
    – MrWhite
    Dec 19, 2016 at 21:23
  • 1
    It is pointed to a php.ini file within the website files. That is, it's inside of the http accessible file structure. Dec 20, 2016 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.