I have an ubuntu server with a handful of custom environment set in /etc/environment as per the ubuntu community recommendation
When I use php from the command line I can use php's getenv()
function to access this variables.
Also, if I run phpinfo()
from the command line I see all of my variables in the ENVIRONMENT section.
HOWEVER:
When trying to access the same data inside processes being run by php5-fpm this data is not available. All I can see in the ENVIRONMENT section of phpinfo()
is:
USER www-data
HOME /var/www
I know the command line uses this ini:
/etc/php5/cli/php.ini
And fpm uses:
/etc/php5/fpm/php.ini
I've not managed to find any differences between the two that would explain why the ENV variables are not coming through in both.
Also if run:
sudo su www-data
and then echo the environment variables I am expecting they are indeed available to the www-data user.
What do I need to do to get my environment variables into the php processes run by fpm?
1. Setting environment variables automatically in php-fpm.conf
2. Setting environment variables manually in php-fpm.conf
! Both methods are described in php-fpm.conf:
I found solution in this github discussion .
The problem is when you run the php-fpm. The process not load the environment.
You can load it in the startup script.
My php-fpm is install by apt-get.
So modify the
and add (beware the space between the dot and the slash)
and modify the /etc/profile to add
In the env.sh. You can
export
the environment whatever you need.Then modify
add
env[MY_ENV_VAR_1] = 'value1'
under the[www]
section.Last. restart the php-fpm. You'll get the environment load by the fpm.
It turns out that you have to explicitly set the ENV vars in the php-fpm.conf
Here's an example: