Maaz Zindani

Loading the index…

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

Apache refuses to start: DefaultRuntimeDir must be a valid directory

ErrorSyntax error on line 80 of /etc/apache2/apache2.conf:

Short answer

DefaultRuntimeDir is where Apache creates run-time files such as shared memory and locks. The error means the path it resolved is not an existing directory. A relative path is resolved against ServerRoot, so check ServerRoot and the folder, then set DefaultRuntimeDir to a directory that exists.

  • 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

    Find every place the directive and ServerRoot are set, and note the exact paths.

    grep -rn "DefaultRuntimeDir\|ServerRoot" /etc/apache2/
  2. 2Match what you see, then jump to its fix

    1. 1The path in the grep output is missing on diskThe directory does not existFix
    2. 2The value has no leading slash (for example logs/ or run/)A relative path is resolved against the wrong ServerRootFix

What does the error look like?

  • Syntax error on line 80 of /etc/apache2/apache2.conf:
  • DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot

Cause 1 of 2

The directory does not exist

1Check

Apache writes its run-time files into this directory, so it has to exist. Look for it.

ls -ld /var/run/apache2

2Fix

Create the directory, or change DefaultRuntimeDir to one that exists.

sudo mkdir -p /var/run/apache2
# or in apache2.conf
DefaultRuntimeDir /var/run/apache2

3Verify

Start Apache and read the status.

sudo systemctl start apache2 && systemctl status apache2 --no-pager

Confirmed by httpd.apache.org

Did this fix it?

Cause 2 of 2

A relative path is resolved against the wrong ServerRoot

1Check

The directive docs say a relative path is taken from ServerRoot, and that ServerRoot should be set before DefaultRuntimeDir, otherwise the default ServerRoot is used.

grep -n "ServerRoot\|DefaultRuntimeDir" /etc/apache2/apache2.conf

2Fix

Use an absolute path, or put the ServerRoot line above the DefaultRuntimeDir line.

ServerRoot "/etc/apache2"
DefaultRuntimeDir /var/run/apache2

3Verify

Start Apache again.

sudo systemctl restart apache2

Confirmed by httpd.apache.org

Did this fix it?

How do I stop it coming back?

  • Prefer absolute paths for run-time directories.
  • Keep ServerRoot at the top of the main config file.
  • When you move the runtime folder, update the directive in the same change.

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.