[CentOS] Apache HTTPD not picking up environment variables.

Fri Oct 23 17:06:00 UTC 2020
Jonathan Billings <billings at negate.org>

On Fri, Oct 23, 2020 at 04:27:34PM +0000, Harold Pritchett wrote:
> I'm trying to install DB2 on a CentOS 7 server.  The problem I'm
> seeing is that the Apache httpd server fails to pick up the db2
> environment variables.  On an older version running under CentOS 5
> this was done by inserting the following lines into the httpd start
> script in /etc/sysconfig/httpd: 
> if test -f /db2home/db2inst1/sqllib/db2profile; then
>   . /db2home/db2inst1/sqllib/db2profile
> fi
> Under CentOS 7's systemctl system this no longer works. I need a
> clue as to where to start looking for where to put this so it will
> be sourced when the Apache server starts.  I have googled this and
> can find nothing relevant.  I even did a "find / -name httpd -print"
> and didn't find anything looking promising. 

In non-systemd systems, httpd was started by a shell script
(/etc/rc.d/init.d/httpd) which sourced the file /etc/sysconfig/httpd,
so you could embed shell code in the file and it would be evaluated.

In systemd systems, the httpd.service unit has:


For systemd units, setting this will cause the systemd unit to read in
the file for variables, but it ignores anything that isn't a simple
'foo=bar' syntax.  It doesn't evaluate shell scripts.

HOWEVER, the logic of your shell script is something that can be
supported by systemd units.  You can say:


and it will only try to source that file for variables if it exists.

So, what you should do is create a directory and file within it


With these two lines in it:


Then run (as root) 'systemctl daemon-reload', and it should
conditionally load the environment variables on startup from that file
if the file exists.

This assumes that /db2home/db2inst1/sqllib/db2profile doesn't have
more shell syntax in it, of course.

See for more details:


Jonathan Billings <billings at negate.org>