Windows – Set Apache specific Environment variables in Windows

apache-2.4environment-variablesservicewindows

I've used Apache in Ubuntu is the past. There is a envvars file contains environment variables used by the Apache Service. I'm unable to find such a file for Windows.

There are two approach that I've found to deal with it. I found Apache read Windows Environment variables. But I don't like this, since they are global and not application specific.

Other option I found is creating a .bat file, set env variables and then start httpd.exe. But the problem with this is that it doesn't works with Apache Service.

Another option I found is to use nssm. It allows to create custom service with service specific environment variables. But I am getting AH00141: Could not initialize random number generator error if I use it.

Is there any other alternative option that I can use?

Best Answer

You can use the SetEnv directive in Apache to setup your own environment variables specific to your application.

More details here https://httpd.apache.org/docs/2.4/mod/mod_env.html#setenv You can put these values inside your Virtual host or httpd.conf