28

Is there any command to find out if apache is running or not.

and on which port except by seeingports.conf files

When i try netstat command then apaches does not appear in that.

but when i use apache2 restart command then it says restart ok

i don't know where it is running

6 Answers 6

26

lsof -i list open ports and the corresponding applications.

For a general check if an app is running you could just use ps aux | grep apache2

1
  • 9
    Or "ps aux | grep httpd" for redhat/centos.
    – lg.
    Apr 13, 2010 at 7:19
28
netstat -anp | grep apache

You could see the listening port and PID from this if it's running.

3
  • 1
    sudo netstat -anp | grep apache Feb 26, 2015 at 5:43
  • It's showing 0.0.0.0:80 in the "Local Address" column. Does it mean apache is running at the same ip address of the machine, on port 80?
    – Rodrigo
    Sep 30, 2015 at 14:33
  • try this netstat -anp | grep -E 'State|java|solr|apache|php|nginx
    – m1m1k
    Nov 3, 2021 at 17:14
6
netstat -tulpn

You'll see the Pid / Binary name on far right column, match this to your running apache instance.

3

If lsof is installed you could try something like this:

lsof | grep httpd

(for centos and friends)

lsof  | grep apache

(for debian and company)

1

If you just want the port number then run

sudo netstat -anp | grep apache | awk 'NR==1{print $4}' | grep -Eo '[0-9]{1,4}'
1
0

For FreeBSD:

sockstat | grep apache httpd

You must log in to answer this question.