44

I have installed Apache on my Ubuntu Server. For a special reason I have to enable mod_rewrite on it. So I have done this.

And in every Tutorial on the internet the last command is to restart apache. But when I do this the console prints [fail].

Can anyone help me here?

$ service apache2 restart 
 * Restarting web server apache2      [fail] 
suspectus
  • 16,548
  • 8
  • 49
  • 57
Miralem Cebic
  • 1,276
  • 1
  • 15
  • 28

6 Answers6

81

I had a similar problem, and for me it was about the logged in user not having privileges so instead of

service apache2 restart

I had to do

sudo service apache2 restart
Sudarshan
  • 8,574
  • 11
  • 52
  • 74
  • 2
    Lol, this makes no sense. We can still do `service apache2 stop` and then `service apache2 start` without `sudo` – Black Mar 07 '17 at 14:03
47

It's telling you some other service is already on port 80, perhaps it's apache

try Code:

sudo /etc/init.d/apache2 stop

followed by Code:

sudo killall apache2

then make sure no services are running on port 80 Code:

sudo netstat -l|grep www

then (re)start apache Code:

sudo /etc/init.d/apache2 restart
s4suryapal
  • 1,880
  • 1
  • 18
  • 26
4

Using the systemd features ( starting from Ubuntu 15) , you can restart apache service as follow :

sudo systemctl restart apache2.service

Check the status:

sudo systemctl status apache2.service
GAD3R
  • 4,317
  • 1
  • 23
  • 34
4

There are various reason for this one .

  1. could be the privilege problem if you have privilege problem then please use sudo for the same .
  2. could be the apache already running in your system then please check the status of the service by running command service apache2 status if they said that [FAIL] apache2 is not running ... failed! it mean it is not running you can start by the command service apache2 start or sudo service apache2 start
  3. if you having not above problem please look at the PID file of apache2 by following command cat /var/run/apache2/apache2.pid which will give you the process ID of the apache it means you system accidentally shutdown without deleting the PID file so delete by following command rm - rf/var/run/apache2/apache2.pid or sudo rm -rf/var/run/apache2/apache2.pid and start again the server by following command service apache2 start or sudo service apache2 start
hardik beladiya
  • 268
  • 2
  • 12
1

I face this issue when I was adding new web site to my web server which is hosted in Digital Ocean Cloud service. So what happened was, when I using sudo commands to restart or reload apache2 server its restring with following error messages.

For me everything worked well despite these two error messages.

  1. Error 1 - Unable to resolve host 'YOUR HOST NAME' .
  2. Error 2 - sum_functio_error() //I don't remember this function name I'll update this later.

So the fix was very simple.

First open your hotsts file.

sudo nano /etc/hosts

Output File

127.0.1.1 hostname 127.0.0.1 localhost

sudo nano /etc/hostname

Output File

hostnamexxx

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – Bugs Jun 23 '17 at 07:48
0

Try below command to restart.

# /etc/init.d/apache2 restart

OR

$ sudo /etc/init.d/apache2 restart

OR

$ sudo service apache2 restart

To stop Apache 2 web server, enter:

# /etc/init.d/apache2 stop

OR

$ sudo /etc/init.d/apache2 stop

OR

$ sudo service apache2 stop

To start Apache 2 web server, enter:

# /etc/init.d/apache2 start

OR

$ sudo /etc/init.d/apache2 start

OR

$ sudo service apache2 start
Dilip Hirapara
  • 14,810
  • 3
  • 27
  • 49