0

In Debian-based systems, it's possible to source a bash script in /etc/apache2/envvars to dynamically set an environment variable. Here is an example:

  • Create a file (/etc/profile.d/myenv.sh) with the content export STARTUP_TIME=$(date '+%Y-%m-%d-%H-%M-%S').
  • Add the line . /etc/profile.d/myenv.sh at the end of /etc/apache2/envvars.
  • Restart apache with sudo systemctl restart apache2.
  • Create a file (test.php) with just <?php phpinfo(); and load the page in a browser to see the value of the variable STARTUP_TIME under "Environment".

There are lots of suggestions to use /etc/sysconfig/httpd in EL systems and declare that as EnvironmentFile in /usr/lib/systemd/system/httpd.service to set env vars, but that file is apparently not a script (see https://superuser.com/a/1817160/777045) thus cannot be used to dynamically set variables.

0

You must log in to answer this question.

Browse other questions tagged .