php 5.4/fcgi on apache 2.4, centos 7.1. php/apache are built/managed by cpanel easyapache.
I’m trying to add an entry to the “environment” section that displays on phpinfo()
I have tried the following :
- SetEnv in httpd.conf – it doesn’t add it as an environment variable, it appears under $_SERVER
- add to /etc/sysconfig/httpd – has no effect whatsoever.
- FcgidInitialEnv MY_VARIABLE SomeValue in httpd.conf – also no effect.
Any advice appreciated. Note this section in phpinfo is NOT for showing system environment variables.
2
Answers
Finally found a solution, the only way that works is to add a wrapper script around the calling of php, and setting the values there - thanks to Oliver Hader for the tip.
Assuming you’re using
mod_fcgi
and you configured a wrapper script like this:The wrapper script
php72wrapper
then defines the environment variables when the request is dispatched to the realphp
binary –MY_VARIABLE
has been added as example:In PHP you could access that value by e.g. using
getenv('MY_VARIABLE')
. Besides thatMY_VARIABLE
is also listed in the “Environment” section ofphpinfo()
.An alternative way is to use
FcgidInitialEnv
in your ApacheVirtualHost
configuration:see https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#fcgidinitialenv