How to export environment variables to Apache httpd in RHEL

Solution Verified - Updated -

Issue

  • How can we export an environment variable to the httpd service and then use it in config files? Is this different between versions of httpd and versions of RHEL?

  • We added environment variables to /etc/sysconfig/httpd and this works in RHEL6, but when we systemctl start httpd in RHEL7, we get errors like this:

    systemd[1]: Ignoring invalid environment assignment 'export MY_CUSTOM_VARIABLE=prod.example.com': /etc/sysconfig/httpd
    
  • In RHEL7 and RHEL8, custom environment variables in /etc/sysconfig/httpd are seen when using apachectl but aren't seen when starting apache with systemctl start httpd.

  • In RHEL7 and RHEL8, custom environment variables in /etc/sysconfig/httpd are seen when using systemctl start httpd but not when using apachectl.

Environment

  • Red Hat Enterprise Linux
  • Apache httpd
  • Custom environment variables exported via /etc/sysconfig/httpd or /etc/systemd/system/httpd*

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content