26

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?

27

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.

1
  • 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? – Mihail Minkov Mar 21 '19 at 0:58
13

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
  • 1
    It is not at all clear how this answers the question. – Randy Cragun Jan 5 '20 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 '20 at 17:29
  • @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 at 7:16
6

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

3
  • 7
    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 '17 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 '17 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 '18 at 16:28
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

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

apache2ctl start
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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.