139

Trying to restart apache from terminal using the following command:

 sudo service apache2 restart

When executing that command, I'm getting below error:

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

On excuting "systemctl status apache2.service" I get this 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'
Artur Meinild
  • 26,018
  • 10
    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
  • 1
    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
  • Thats good to hear – grag42 May 29 '15 at 21:12
  • 4
    Possible duplicate of Apache not starting – rancho Aug 01 '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 05 '16 at 13:52
  • In my case case port 80 was taken, so I had to shut it down, sudo fuser 80/tcp -l , after this I was able to start apache – Armin Jan 30 '20 at 20:10

12 Answers12

132

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.

Eliah Kagan
  • 117,780
rancho
  • 4,036
89

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
Arek
  • 996
40

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
Parto
  • 15,325
  • 24
  • 86
  • 117
6

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....

Videonauth
  • 33,355
  • 17
  • 105
  • 120
5

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
3

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

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

Bruce Tong
  • 151
  • 3
2

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

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.

MadBoy
  • 601
1

For what it may be relevant at this stage, but today I came across the same problem and it turned out to be an issue with the certificate file.

So eventually the config was all ok, but in uploading the new .crt content I did in the wrong file, meaning there were no more matching for a particular site and the whole server was refusing to start.

No indication of incorrect SSL certificate in the log or anywhere else, which took me a while to figure out.

1

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 :)

1

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.

muru
  • 197,895
  • 55
  • 485
  • 740
1

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.