6

How do I stop my local apache server?

/etc/init.d/apache2 and service apache2 give only 3 options -- restart, startand status


I rebooted my syetem and now sudo /etc/inid.d/apache stop works but doesn't give the stop option on TAB

httpd was missing so I did sudo ln -s /usr/sbin/apachectl /etc/init.d/httpd -- read it on some forum

The httpd service now gives start and status option (Again, no stop)

doing sudo /etc/init.d/httpd status says

Looking up localhost
Making HTTP connection to localhost
Alert!: Unable to connect to remote host.

lynx: Can't access startfile http://localhost/server-status
'www-browser -dump http://localhost:80/server-status' failed.
Maybe you need to install a package providing www-browser or you
need to adjust the APACHE_LYNX variable in /etc/apache2/envvars

I did install lynx just before making the link by sudo apt-get install lynx

Why is only the stop missing? This is just plain weird ...

8
  • have you tried sudo service apache2 stop.. it has a stop command.. more > help.ubuntu.com/community/… – AzkerM Jan 15 '14 at 8:51
  • Yes I did, it says stop: Unknown job: apache2 – Sourabh Jan 15 '14 at 8:52
  • 1
    /usr/sbin/apache2ctl stop says AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message httpd (pid 1491?) not running – Sourabh Jan 15 '14 at 8:55
  • Could you just backup its configuration and reinstall it? – user.dz Jan 19 '14 at 20:31
  • I tried re-installing but as I've read in many places, apache2 is a meta-package, and I think many of its dependencies were installed manually so finding and removing all of them is not possible (for me at least) – Sourabh Jan 19 '14 at 20:56
2

Here's how i kill it:

$ sudo service apache2 stop

make sure it is off, or that the process isn't running

ps -elf | grep apache
0 S j0h      14733 24786  0  80   0 -  1108 pipe_w 08:22 pts/1    00:00:00 grep --color=auto apache

(says the only instance of Apache is my query)

Starting back up:

sudo service apache2 start

Other methods, include

$sudo service apache2 graceful-stop

You could kill apache2 many other ways:

$sudo pkill apache2

$sudo kill -9 <apache PID>

(find apache's pid ps aux | grep apac) or use top to find the PID of apache2)

This line:

sudo /etc/inid.d/apache stop

you probably meant init.d

That might just be a typo though, I am not sure.

2

You could also use the apache2ctl command.

sudo apache2ctl stop

That handles the service and all in a short command. Other commands like start, restart are also supported.

1

Okay! Apache is restarting successfully but just isn't sure where that it want serve from, as it is choosing your localhost (127.0.0.1) by default. To prevent this message from appearing, add the following line into your /etc/apache2/apache2.conf file:

ServerName localhost

P.S.: Make sure that you want to serve from localhost (127.0.0.1)

More: How to fix Apache – "Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName" Error on Ubuntu

3
  • Now /usr/sbin/apache2ctl stop says httpd (pid 19157?) not running. /etc/apache2/httpd.conf file is missing, is that weird? – Sourabh Jan 15 '14 at 9:08
  • Okay! may be the file is not listed under conf.. try adding Include httpd.conf at the end of apache2.conf file then restart the service. let me know how it goes.. Also make sure you back up each file before you do any changes. :) – AzkerM Jan 15 '14 at 9:12
  • I think the missing httpd.conf is normal. ubuntuforums.org/showthread.php?t=2116503 – Sourabh Jan 15 '14 at 9:20
1

$ sudo service apache2 stop

worked for me . I was getting error while starting tomcat7 in eclipse but it show error "Port already in use for 8080 and 8005" as the ports were already acquired by apache2 (i.e for php server).

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.