71

Trying to restart apache from terminal using following command:

 sudo service apache2 restart

when executing that command getting below error:

Job for apache2.service failed. See "systemctl status apache2.service" and "journalctl -xe" for details.

On excuting "systemctl status apache2.service" got below output

apache2.service - (null)
   Loaded: loaded (/etc/init.d/apache2)
   Active: failed (Result: exit-code) since Sat 2015-05-30 02:22:41 IST; 12s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 4866 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)

apache error.log

AH00489: Apache/2.4.12 (Unix) configured -- resuming normal operations
AH00094: Command line: '/usr/local/apache2/bin/httpd'
  • 6
    after you run the apache2 restart and get that error, run sudo journalctl -xe that will give you a better idea about what happened. if you still have issues understanding it. Post the results here. – grag42 May 29 '15 at 20:50
  • ok. That didn't help me either. What is in the apache log files. /var/log/apache2/error.log – grag42 May 29 '15 at 20:56
  • @grag42 thanks for your suggestion, I ran sudo journalctl -xe and found some rewrite rule issue was there and fixed it and its running now. – Gautam Savaliya May 29 '15 at 21:10
  • 4
    Possible duplicate of Apache not starting – rancho Aug 1 '16 at 18:15
  • 3
    @rancho: What leads you to believe the question is a duplicate? The linked question contains a quite specific error message which we don't have here. The possible causes for OP's issue a pretty unclear at this moment. – David Foerster Aug 5 '16 at 13:52

11 Answers 11

62

Maybe this will help to find the cause:

journalctl | tail

In my case it was a mistake in the configuration file:

AH00526: Syntax error on line 5 of /etc/apache2/sites-enabled/mydomain-wsf.lan.conf
  • 6
    No journal files were found. – Stevie G Sep 9 '15 at 19:27
  • 5
    @StevieG, try sudo journalctl | tail – Dherik Dec 9 '15 at 12:36
  • 1
    What did you do to fix the thing? – Léo Léopold Hertz 준영 Jun 22 '16 at 15:42
  • in my case, i also did a mistake in the apache2.config file – alamin Sep 1 '16 at 7:41
  • Thanks. I wrong typed my directory for my newly added site conf. – Lynnell Emmanuel Neri Feb 28 '18 at 3:52
48

There is some syntax error in the file apache2.conf.

In a terminal, type:

cd /etc/apache2

Then:

apache2ctl configtest

It will show you where is the error in the apache2.conf file to correct.

  • 1
    great approach tnx, saved my time – George Garchagudashvili Nov 3 '17 at 18:52
  • 1
    This is fantastic. – abalter May 24 '18 at 5:03
  • 1
    Thanks. Was a problem with redmine and PassengerResolveSymlinksInDocumentRoot option. – Vadim Jun 19 '18 at 5:24
  • lol, after execute: apache2ctl configtest got syntax ok, but when i run apache2 --help got apache2: Syntax error on line 82 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot and no errors in apache error.log ! – Vladimir Ch Apr 5 at 18:52
  • after see closely to /etc/apache2/sites-enabled/ dir, i noticed, that i got file, not symbolic linc to site.conf + reenable mod php5.6 (sudo a2dismod php5.6 ; sudo a2enmod php5.6) my service apache2 has been started without "ohh-ahh" – Vladimir Ch Apr 5 at 19:19
19

The problem is because some configuration files are deleted, you have to reinstall it.

REINSTALL APACHE2:

To replace configuration files that have been deleted, without purging the package, you can do:

sudo apt-get -o DPkg::Options::="--force-confmiss" --reinstall install apache2

To fully remove the apache2 config files, you should:

sudo apt-get purge apache2

which will then let you reinstall it in the usual way with:

sudo apt-get install apache2

Purge is required to remove all the config files - if you delete the config files but only remove the package, then this is remembered & missing config files are not reinstalled by default.

Then REINSTALL PHP5:

apt-get purge libapache2-mod-php5 php5 && \
apt-get install libapache2-mod-php5 php5
2

Problem:

Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.

Solution:

  • To fully remove the apache2 config files, you should:

    1) sudo apt-get purge apache2

  • which will then let you reinstall it in the usual way with:

    2) sudo apt-get install apache2

==> It Works fine...

thanks....

2

I got the same error after removing a virtual host. The problem was the lingering SSL conf file associated with that host located in /etc/apache2/sites-enabled. The SSL was through Let's Encrypt so the code for me to remove was:

sudo rm yourdomain.com-le-ssl.conf
1

I got the Same errors While working with .htaccess

I just put this command

<Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
</Directory>

in /etc/apache2/sites-enabled/000-default.conf this folder

after adding this i have getting the error

then i delete these peace of command from the file and my error has resolved.

1

you most likely have a syntax error. for me it was in my 'sites-enabled' folder.

i mis-spelled 'ServerAlias' to 'ServerAlisa'.

0

This is mostly a configuration error. I just now had an old site enabled on apache, what caused this error. So I had to disable it before reloading apache.

sudo a2dissite <my-site>
sudo service apache2 reload

Problem solved :)

0

Thank you for your help! I was able to install correctly with Solution:

To fully remove the apache2 config files, you should:

  1. sudo apt-get purge apache2 which will then let you reinstall it in the usual way with:

  2. sudo apt-get install apache 2

It now works fine.

0

I think the problem is that you have some site enabled but you deleted its configuration file. Try disabling the site with sudo a2dissite "name" and then restart apache server. At least this was the problem for me and this action solved it.

0

In my case, the error started to appear after doing apt upgrade. After playing a lot I went to following directories to see what I can disable.

  • /etc/apache2/mods-enabled - a2dismod (to turn back on a2enconf)
  • /etc/apache2/conf-enabled - a2disconf (to turn back on a2enconf)

In my case, I had to those MODS enabled.

enter image description here

It seems that apt-upgrade must have removed/broken php7.2 because as soon as I disabled it and restarted everything worked. Of course, in anyone else's case, it may be something different. When Apache crashes it may be bad config or bad mod. You have to pick your battles.

protected by Community Oct 12 '17 at 4:04

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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