0

I'm using Ubuntu 18.04. I would like to define some env vars in a single place that are both accessible system-wide (via a shell) and in my Apache-Python application. In /etc/profile, I have defined

export MY_ENV_VAR1=envvar1
export MY_ENV_VAR2=myvalue1
...

Then I have /lib/systemd/system/apache2.service

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
Environment=APACHE_STARTED_BY_SYSTEMD=true
Environment=MY_ENV_VAR1=envvar1
Environment=MY_ENV_VAR2=value1
...

I have set up these env vars so that in my Apache config file (/etc/apache2/sites-available/000-default-le-ssl.conf), I can have

    PassEnv MY_ENV_VAR1
    PassEnv DB_USER

Is there some way I can define these vars only in a single place and then reference them from one file the other?

1 Answer 1

0

One possibility is to put the variables in file /etc/environment in the form

MY_ENV_VAR1=envvar1
MY_ENV_VAR99="value with spaces"

and these will be read and exported by pam_env on login. To have apache read the same file use

EnvironmentFile=/etc/environment

in the unit file. Note, the use of this keyword is not liked by the systemd designers so perhaps one day it will be deprecated, and then removed, but to be pragmatic it works for now. Beware of using any special characters in the variables, as pam and systemd do not parse them in the same way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .