16

Update: Responding to the comment:

check processes of apache:

$ ps a | grep apache 3
grep: 3: No such file or directory
$ ps a | grep apache
 4514 pts/0    S+     0:00 grep --color=auto apache
$ ps a | grep apache2
 4516 pts/0    S+     0:00 grep --color=auto apache2

checking apache error log

$ tail /var/log/apache2/error.log
[Sun Aug 07 03:14:19 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.5 with Suhosin-Patch configured -- resuming normal operations
[Mon Aug 08 03:13:58 2011] [notice] Graceful restart requested, doing restart
[Mon Aug 08 03:14:00 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.5 with Suhosin-Patch configured -- resuming normal operations
[Mon Aug 08 09:03:16 2011] [notice] caught SIGTERM, shutting down
[Mon Aug 08 09:05:47 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.5 with Suhosin-Patch configured -- resuming normal operations

Original: I have stopped apache, but why it still has the same number of processes running?

$ ps -A | grep apache
 1663 ?        00:00:00 apache2
 1667 ?        00:00:00 apache2
 1668 ?        00:00:00 apache2
 1669 ?        00:00:00 apache2
 1670 ?        00:00:00 apache2
 1671 ?        00:00:00 apache2
$ /etc/init.d/apache2 stop
 * Stopping web server apache2                            [ OK ] 
$ ps -A | grep apache
 1663 ?        00:00:00 apache2
 1667 ?        00:00:00 apache2
 1668 ?        00:00:00 apache2
 1669 ?        00:00:00 apache2
 1670 ?        00:00:00 apache2
 1671 ?        00:00:00 apache2

Thanks!

3
  • (Sorry I can't comment 'cause I've not enough rep.) 1. Is the web servier still available with a web browser? 2. Check the status of your processes. They may have become "Zombie processes" ps a | grep apache 3. Check the error logs, the may be useful tail /var/log/apache/error.log
    – SamK
    Aug 8, 2011 at 13:45
  • 1. I am using firefox. It is my laptop. 2 and 3 see my update.
    – Tim
    Aug 8, 2011 at 14:08
  • Have u tried this 'apache2 -k stop' or a 'apache2 -k restart'? or a restart of your system?
    – blade19899
    Sep 10, 2012 at 12:15

7 Answers 7

28

This can happen occasionally when Apache refuses to stop nicely or has Zombie Processes. For the former you can kill all running processes with sudo killall -9 apache2; however, for the latter you'll simple need to wait for them to go away. In the event it's Apache not wanting to stop nicely, what you'll really want to do is investigate what's going on. Finding out exactly what's going on can be difficult though.

An interactive strace of the process id may lend a clue as to what site(s) are acting up and causing issues. From your above ps -A you can check the first process with

strace -p 1663

This will attach to the running processes stack trace providing live output of what is going on. At any time you can Ctrl+C

An additional resource is the main error log for Apache this can be found in /var/log/apache2/error.log You'll want to get a decent chunk of the log and skim it for details. If the problem is an ongoing issue running

tail -f /var/log/apache2/error.log

This similar to the strace will run in realtime. For the last N lines replace -f with -# where the # is a positive number like 50, 100, 282, etc.

8

Make sure you have proper permissions to stop the service.

If you run:

service apache2 stop

you will not get any error just:

* Stopping web server apache2

Try:

sudo service apache2 stop      
1
  • when there is not enough memory or swap nearly full , this will fail, killall is the only solution
    – James Tan
    Apr 23, 2018 at 4:53
4

I too had the same problem, and tried the following:

sudo apache2ctl stop

to stop the service, and

sudo apache2ctl start

to start it again.

It works for me, any possible suggestions are welcome.

1

The command systemctl stop apache2 worked for me.

0

Processes can be asked (by sending a signal to them) to stop. The kill command is a way to do that. If you know the process ID (PID) of the process, it can be asked nicely by running the command below in a terminal:

kill PID_OF_YOUR_PROCESS

The above example sends the PID the default TERM signal (code 15). You can look up the signal codes in the man page of kill (man kill).

When the program disregards the TERM signal sent to them, it is still possible to apply a bit more pressure by sending the KILL signal (code 9). This signal is used as a last resort, because the process might not save any unsaved data.

Specifying a -SIGNAL_CODE as the first parameter before the process ID will send the process the specific signal. Another useful feature of the kill command is that you can specify more PIDs as in the following example:

kill -9 PID1 PID2 PID3 PID4

Try to terminate the Apache processes by using the kill -9 line. They should stop unless something blocks them from doing so.

1
  • If the reader isn't familiar with the 'kill' command, there's almost no chance they're going to know how to find the PID of the apache2 process. Jun 9, 2018 at 21:55
0

I had the same problem but you can't just do one service apache2 stop command - you have to do one PER process. Then, you MAY want to add a sudo in front just in case you're logged into some odd account that needs it so if you see 9 processes running, do 9 sudo service apache2 stop

Worked great for me.

-1

After installing nginx my apache stopped working properly. Seems to in some cases apache confusing with nginx. Just remove nginx

sudo apt-get purge nginx nginx-common
sudo apt-get autoremove
1
  • I guess if nginx has been started, and is using the default port which apache would otherwise use, this could be an explanation.
    – Ed Randall
    May 29, 2020 at 20:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .