14

I am trying to create a web server on my ubuntu 18.04 so i installed Apache2 but i can't start it. Here's what appeared when i run the systemctl status apache2.service command

apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Sat 2020-02-22 13:58:09 CET; 34s ago
  Process: 2791 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
Feb 22 13:58:09 moemen apachectl[2791]: AH00558: apache2: Could not reliably determine the server's
Feb 22 13:58:09 moemen apachectl[2791]: (98)Address already in use: AH00072: make_sock: could not b
Feb 22 13:58:09 moemen apachectl[2791]: (98)Address already in use: AH00072: make_sock: could not b
Feb 22 13:58:09 moemen apachectl[2791]: no listening sockets available, shutting down
Feb 22 13:58:09 moemen apachectl[2791]: AH00015: Unable to open logs
Feb 22 13:58:09 moemen apachectl[2791]: Action 'start' failed.
Feb 22 13:58:09 moemen apachectl[2791]: The Apache error log may have more information.
Feb 22 13:58:09 moemen systemd[1]: apache2.service: Control process exited, code=exited status=1
Feb 22 13:58:09 moemen systemd[1]: apache2.service: Failed with result 'exit-code'.
Feb 22 13:58:09 moemen systemd[1]: Failed to start The Apache HTTP Server.

I'm new at this can you please help me

Vasil Velichkov
  • 1,236
  • 11
  • 17
moe_
  • 219
  • 2
  • 3
  • 15

6 Answers6

33

I also faced same problem.

First check

$ sudo systemctl status nginx

If nginx is active then stop this with

$ sudo systemctl stop nginx

then again try to start apache2 server in different terminal.

Greenonline
  • 1,330
  • 8
  • 23
  • 31
8

first remove apache2

sudo apt-get --purge remove apache2 sudo apt-get autoremove

after that if there files (.conf) /etc/sites-available remove them using

rm example.com.conf

then install again sudo apt-get install apache2

now it will fixed check it now sudo ufw allow 'Apache' sudo systemctl status apache2

csanjeewag
  • 152
  • 1
  • 2
  • After spending several days, troubleshooting my problem stopped with this answer. Thank you! (HINT: In addition to removing and reinstalling apache2, should remove /etc/apache2 directory as it contains remnants from the now-removed installation.) – TheGeeko61 Jun 05 '21 at 13:45
4

Let me give a more general answer than the first 2. One possible problem with Apache is, when we try to run it, it may fail because port 80 is used by another software:

  • a common case is nginx which is covered by Devashish Mishra
  • in my case it was a server app that I deployed (in node.js, I had to tell pm2 to stop it)
  • in general, you may want to find what uses port 80. This may be done like Chi.C.J.Rajeeva Lochana has suggested: install netstat if you don't have it (sudo apt install net-tools), use it: sudo netstat -antup | grep 80. It will show some lines which may include :::80 or <your IP>:80 which will tell what is listening to the port

Once you've found what listens to the 80 port, you have to decide what to do with it. For instance, if that's nginx and you don't use it, you may go like Devashish Mishra has suggested: just stop it (sudo systemctl stop nginx). Likewise, you can stop or kill (sudo killall -9 program-name) other programs. However, if you need them, you'll also need to further configure Apache and rerun them (the exact steps highly depend on the case).

YakovL
  • 7,557
  • 12
  • 62
  • 102
2

Please read this carefully.

Perform the following command, and if you see it is apache, then do the following below the command.
Note: You need to install the net-tools package before you could run netstat. Run sudo apt install net-tools to install it.

sudo netstat -antup | grep 80

You should check the line with something like <Your IP>:80.
Please note that this might also happen when you uninstall Apache when it is running.

The command could be:

sudo killall -9 program-name

Replace program-name with the program's name if the program running on port 80 is not stoppable. Let me know it it doesn't work. Thanks.

Example person
  • 3,198
  • 3
  • 18
  • 45
2

I found this problem and was able to solve it by creating a folder /var/log/apache2, I checked in the /var/log/ folder, it turns out that there is no apache2 folder, just like in the case of mysql that won't start.

seen from your log that

Feb 22 13:58:09 moment apachectl[2791]: AH00015: Unable to open logs

maybe this will help

Memet_
  • 19
  • 3
-2
  1. On your terminal.
  2. Type: sudo stop /etc/init.d/apache2

The response will be:

Stopping apache2 (via systemctl): apache2.service.

  1. Now start the server:
sudo /opt/lampp/lampp start

If you installed lamp correctly this should work

Tyler2P
  • 2,324
  • 26
  • 22
  • 31