39

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?

9 Answers 9

50

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.

2
  • 1
    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? Mar 21, 2019 at 0:58
  • I used to run apache2 --version to see if any error occurs.
    – Ibrahim.H
    Jul 23, 2021 at 14:49
19

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

3
  • 2
    It is not at all clear how this answers the question. Jan 5, 2020 at 4:18
  • 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.
    – 71GA
    Nov 19, 2020 at 17:29
  • 1
    @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.
    – Lyubomir
    Mar 3, 2021 at 7:16
7

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

4
  • 8
    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
    – Peshmerge
    Oct 29, 2017 at 23:17
  • 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.
    – Niyol
    Oct 31, 2017 at 10:00
  • 1
    @Peshmerge THanks! can you tell me how to retain it after reboot? it seems on reboot we have to manually execute that command everytime
    – T.Todua
    Oct 19, 2018 at 16:28
  • Works with docker :)
    – JRichardsz
    Oct 12, 2023 at 20:32
2

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

apache2ctl start
1

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"

1

I had this issue with Ubuntu 20.14 and Apache2 after running Vagrant. My resolution was to change the Document Root in

/etc/apache2/sites-enabled/000-default.conf

Before Change -> DocumentRoot /var/www/HTML

I deleted the "HTML" (because I am not using the HTML directory (this is just for development no production)

After Change -> DocumentRoot /var/www/

I then restarted Apache

sudo systemctl stop apache2
sudo systemctl start apache2

and all is well.

0

Reenebling php5.6 apache module helps to fix this problem.

Press Ctrl+Alt+T and type these:

sudo a2dismod php5.6
sudo a2enmod php5.6

Then restart apache2 service:

sudo service apache2 restart
0

I have just had this error and run through all the ideas given and none worked. What I had done was changed the URL in the sites-available .conf file, restarted apache and boom. It stopped working. The solution is to go into sites-enabled and remove the old file there and then restart apache2. I hope that helps someone!

0

Here is the answer of which I found;

apache2 -S replied;

apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir takes one argument, Common directory for run-time files (shared memory, locks, etc.)

Line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir ${APACHE_RUN_DIR}

Line 86 gave away the /etc/apache2/envars file which shows this:

export APACHE_PID_FILE=/var/run/apache2$SUFFIX/apache2.pid

export APACHE_RUN_DIR=/var/run/apache2$SUFFIX

export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX

Indicating the environment is set.

Looking at the /var/run/apache2 folder, it is owned by Root.

Run: chown -R www-data:www-data /var/run/apache2

Which should now allow the non-root user running Apache2 to write to the folder Re-run systemctl restart apache2

apache2 -S Now works properly.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .