Ubuntu Apache2 DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot

97,611

Solution 1

The command

source /etc/apache2/envvars

sorted my problem out (after trying ALL the others).

To check whether all is well or not use the command

apache2 -S

I found that was quicker than using my DNS records.

Solution 2

There is a missing update in "man apache2", at least for option -V;

Today, one should use either "apachectl" or "apache2ctl" instead of

"apache2" for at least some options, as stated in

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=879571

Solution 3

Apache2 uses /etc/apache2/envvars to set environment variables. You can use this information to make sure the directory ${APACHE_RUN_DIR} points to is valid.

I was experiencing the same issue while upgrading from 14.04 to 17.04. Problem was: ${APACHE_RUN_DIR} was set to /var/run/apache2, but the apache2 folder was missing in /var/run.

The fix for me was: mkdir /var/run/apache2

Solution 4

in my case it was regarding "Require all denied" line in apache2.conf file which (again) in my case was typed in as just "Require denied"

Solution 5

Had the same problem, and could solve it by using:

apache2ctl start
Share:
97,611

Related videos on Youtube

Grayson Kent
Author by

Grayson Kent

Linux Systems Engineer by day. Mess with trendy web technologies at night.

Updated on September 18, 2022

Comments

  • Grayson Kent
    Grayson Kent over 1 year

    I have a web server running Ubuntu 17.04 that I am attempting to set up with Apache. Everything ran great until I decided to host two websites on a single machine through virtualHosts. Now apache refuses to start up with even a single host enabled. Each time I attempt to start Apache I get this error:

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

    None of my attempts to fix this have come to anything including:

    apt purge apache2 && rm -r /etc/apache2 
    

    All line 80 of the error message tells me is DefaultRuntimeDir ${APACHE_RUN_DIR}.

    And at no time do I see where or what APACHE_RUN_DIR is declared as.

    Can someone help me out?

  • Peshmerge
    Peshmerge over 6 years
    even if you created the folder or if the folder is already presented (like in my situation) you have to have to run the following command. source /etc/apache2/envvars
  • Niyol
    Niyol over 6 years
    you only need to run the envvares command if you are starting Apache without the startscript, if you are using init.d/system.d the file will be sourced automatically.
  • T.Todua
    T.Todua over 5 years
    @Peshmerge THanks! can you tell me how to retain it after reboot? it seems on reboot we have to manually execute that command everytime
  • Mihail Minkov
    Mihail Minkov about 5 years
    I used the source /etc/apache2/envvars but after that my home directory changed from ~ to home and when I wrote cd it showed -bash: cd: HOME not set. When I entered the envvars one of the first lines is # this won't be correct after changing uid and unset HOME. Any idea how to fix this?
  • Randy Cragun
    Randy Cragun over 4 years
    It is not at all clear how this answers the question.
  • 71GA
    71GA over 3 years
    This is the key information because everything worked for the user. Users should not use apache2 but apache2ctl and this is written in the main apache configuration file.
  • Lyubomir
    Lyubomir about 3 years
    @RandyCragun This answer helped me because running apachectl actually showed the error not on line 80 of apache2.conf, but in my config file for the site. It actually showed that the error was an unknown directive because of mod_rewrite not being enabled.
  • Ibrahim.H
    Ibrahim.H almost 3 years
    I used to run apache2 --version to see if any error occurs.