我在Ubuntu中使用Apache是过去的。 有一个envvars
文件包含Apache服务使用的环境variables。 我无法为Windowsfind这样的文件。
有两种方法,我发现处理它。 我发现Apache读取Windows环境variables。 但我不喜欢这个,因为它们是全球性的,而不是特定的应用程序。
我发现其他选项是创build一个.bat文件,设置envvariables,然后启动httpd.exe
。 但是这个问题是它不适用于Apache服务。
我发现的另一个select是使用nssm 。 它允许使用服务特定的环境variables创build定制服务。 但是我越来越AH00141: Could not initialize random number generator
如果我使用它, AH00141: Could not initialize random number generator
错误。
有什么其他的select,我可以使用?
您可以使用Apache中的SetEnv指令来设置您自己的特定于您的应用程序的环境variables。
更多细节在这里https://httpd.apache.org/docs/2.4/mod/mod_env.html#setenv你可以把这些值放在你的虚拟主机或httpd.conf
我最终编写了一个replacehttpd.exe
的包装器。 我将httpd.exe
重命名为httpd2.exe
并使用这个包装器httpd.sh
来执行它。 在启动apache服务之前,它基本上暂时设置系统环境variables。 一旦服务启动,它将删除它们。
#!/bin/bash PHP_INI_SCAN_DIR="C:\Server\PHP\7.0\conf;C:\Server\Config\PHP" if [ "stop" == "$*" ]; then exec /c/Server/Apache/bin/httpd2.exe -k stop elif [ "" == "$*" ]; then export PHP_INI_SCAN_DIR echo "Starting Apache in console mode" /c/Server/Apache/bin/httpd2.exe elif [ "start" == "$*" ]; then /bin/regtool set "/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session Manager/Environment/PHP_INI_SCAN_DIR" "$PHP_INI_SCAN_DIR" -s /c/Server/Apache/bin/httpd2.exe -k start /bin/regtool unset "/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session Manager/Environment/PHP_INI_SCAN_DIR" elif [ "restart" == "$*" ]; then #/bin/regtool set "/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session Manager/Environment/PHP_INI_SCAN_DIR" "$PHP_INI_SCAN_DIR" -s #/c/Server/Apache/bin/httpd2.exe -k stop #/c/Server/Apache/bin/httpd2.exe -k start #/bin/regtool unset "/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session Manager/Environment/PHP_INI_SCAN_DIR" /c/Server/Apache/bin/httpd2.exe -k restart # ENV don't reload this way :( else /c/Server/Apache/bin/httpd2.exe "$*" fi