I would like to be able to regenerate the value held by the environment variables inside my testing environment, and have the new values be read by PHP-FPM.
I have written a script that regenerates the environment variables, writes them to a file, and restarts PHP-FPM
# make errors error
set -eufx -o pipefail
# Generate the env settings file
php bin/cli.php genEnvSettings dev /etc/profile.d/imagickdemos.sh
# reload the env values
set +u
source ~/.bashrc
source ~/.bash_profile
set -u
#restart PHP-FPM
/etc/init.d/php-fpm restart
Running this script does not change the environment variables that PHP-FPM receives.
If I run the following commands directly from the CLI after running the above script:
source ~/.bash_profile
/etc/init.d/php-fpm restart
Then the new values for the environment variables are available to PHP-FPM. i.e. it's as if source ~/.bash_profile
inside the script has no effect.
How can I reload the environment variables inside that script, rather than having to run the reload directly from the command line? Or is there a better way to make a newly written env settings file be picked up when restarting a service?
I am using Centos 6.4 in case that makes any difference.
My guess is that your .bash_profile has a condition like
if [ -n "$PS1" ]
which makes it effective for interactive shells only. The way to test it is toset -x
in the script and inspect the trace output for the assignments.As to your other question: the usual way to set a server's environment is to write the export assignments to
/etc/sysconfig/servername
or/etc/default/servername
(whichever one is sourced directly by the init.d script).It sounds like sourcing the env scripts from within the init.d script is the standard practice, but the actual issue that was stopping the env script being reloaded for me was the
set -f
flag.In the file /etc/bashrc it looks like it should be sourcing the files no matter what:
But the -f flag turns off file-globbing. I've removed the -f flag and instead changed to
shopt -s failglob
which errors on failed globbing.