Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Apache warns that a ${VAR} config variable is not defined

ErrorConfig variable is not defined

Short answer

Apache expands ${VAR} from Define or from the shell environment that exists when the server starts. If the name is in neither, the text stays as written and a warning is logged. Start Apache through apachectl so its envvars file is loaded, or add a Define. SetEnv does not work here.

  • Applies to Apache httpd 2.4, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the syntax check as your normal service would, and read which variable name Apache complains about.

    apachectl -t
  2. 2Match what you see, then jump to its fix

    1. 1The warning names variables you never defined yourself, and it appears only when you run the httpd binary directlyApache was started without its envvars fileFix
    2. 2The variable exists in the site config, but Apache still logs that it is not defined at startThe variable is set with SetEnv or defined too lateFix
    3. 3A name in your own config, such as ${MY_APP_ROOT}, is reported and nothing sets it anywhereThe variable name is misspelled or never exportedFix

What does the error look like?

  • Config variable is not defined
  • ${VAR} left unchanged in the configuration, with a warning in the error log

Cause 1 of 3

Apache was started without its envvars file

1Check

apachectl sets the environment variables Apache needs and then runs httpd. Starting the binary yourself skips that step, so those variables do not exist. Compare the two ways of starting.

apachectl -t
httpd -t

2Fix

Start and test through apachectl. If you must run the binary, load the envvars file from your install in the same shell first; the docs show it next to apachectl, and its location depends on how Apache was built or packaged.

apachectl configtest
apachectl restart

3Verify

The syntax test passes and no 'is not defined' line appears.

apachectl -t

Confirmed by httpd.apache.org

Did this fix it?

Cause 2 of 3

The variable is set with SetEnv or defined too late

1Check

Only shell environment variables set before the server starts, or Define values, can be used in ${VAR} expansion. SetEnv takes effect too late for that.

grep -rn -E 'SetEnv|Define' /etc/apache2/ /usr/local/apache2/conf/ 2>/dev/null

2Fix

Use Define for a value that belongs in the config, and reference it with ${NAME}. Define wins over a shell variable of the same name.

Define DOCROOT /var/www/html
DocumentRoot "${DOCROOT}"

3Verify

Test the configuration again.

apachectl -t

Confirmed by httpd.apache.org

Did this fix it?

Cause 3 of 3

The variable name is misspelled or never exported

1Check

When the name is not found, Apache leaves the characters ${VAR} unchanged and logs a warning. Search every place that should set the name.

grep -rn 'MY_APP_ROOT' /etc/apache2/ /usr/local/apache2/conf/ 2>/dev/null

2Fix

Correct the spelling, or add a Define (or export the variable in the environment that launches Apache, before it starts).

Define MY_APP_ROOT /srv/my-app

3Verify

Run the syntax test and restart.

apachectl -t
apachectl graceful

Confirmed by httpd.apache.org

Did this fix it?

How do I stop it coming back?

  • Always run apachectl -t before a restart.
  • Prefer Define over environment variables for values that live in the Apache config.
  • In containers, set the environment variable in the image or entrypoint before Apache starts.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.