How can I determine if Apache is installed on a system?

28

9

I have Linux Mint on my computer but I don't know how to find out whether Apache2 is on it or where it is actually installed. I run my web browser (PHP installed) with http://localhost as a URL and it works.

Thach Xuyen

Posted 2012-02-09T14:03:19.260

Reputation: 463

you want to know the path where are the files from that site? – Francisco Tapia – 2015-04-24T17:03:25.467

what do you mean by PHP installed? – onemach – 2012-02-09T14:06:29.057

How is that related to c, c# or unix? – ThiefMaster – 2012-02-09T14:08:01.440

Answers

43

I would recommend

dpkg --get-selections | grep apache

It lists all installed packages that contain "apache" in their name. For example:

apache2                                         install
apache2-doc                                     install
apache2-mpm-prefork                             install
apache2-utils                                   install
apache2.2-bin                                   install
apache2.2-common                                install
libapache2-mod-php5                             install
libapache2-svn                                  install

It indicates that the package apache2 is installed on the system.

Another approach, to find any running HTTP daemon on the default port would be:

sudo lsof -nPi | grep ":80 (LISTEN)"

Which lists something like:

apache2    1026     root    4u  IPv6    3739      0t0  TCP *:80 (LISTEN)
apache2    3966 www-data    4u  IPv6    3739      0t0  TCP *:80 (LISTEN)
apache2    4014 www-data    4u  IPv6    3739      0t0  TCP *:80 (LISTEN)
apache2    4015 www-data    4u  IPv6    3739      0t0  TCP *:80 (LISTEN)
apache2    4016 www-data    4u  IPv6    3739      0t0  TCP *:80 (LISTEN)

Der Hochstapler

Posted 2012-02-09T14:03:19.260

Reputation: 77 228

-bash: dpkg: command not found is the above done in a certain directory? – elliotrock – 2017-06-19T01:04:48.907

@elliotrock No, try running it with sudo. – Der Hochstapler – 2017-06-19T09:03:23.327

-bash: dpkg: command not found same error on aws linux even tried with sudo. – Krishnadas PC – 2018-07-04T12:28:11.897

1This question is about Linux Mint. Using dpkg on platforms that don't have it is pointless. – Der Hochstapler – 2018-07-04T12:39:13.280

12

Try the which command:

# which apache2

In my experience, the Apache binary is located in /usr/sbin on most installations.

Frédéric Hamidi

Posted 2012-02-09T14:03:19.260

Reputation: 430

4Depending on distro you might also try which with 'apache' and 'httpd' – siliconrockstar – 2015-04-24T17:00:05.210

4

To check whether if apache is running or not (the status), type:

sudo service apache2 status

at the command line.

Sukhpreet Singh

Posted 2012-02-09T14:03:19.260

Reputation: 41

This only works where Apache is installed as a (sysv etc) service; which admittedly will cover a lot of cases. – bertieb – 2015-08-24T08:03:53.450

3

Just do a which httpd as user root.

Abrixas2

Posted 2012-02-09T14:03:19.260

Reputation:

2Afraid to say, but on Mint (a Debian derivative) it would be apache or apache2, but not httpd ... – 0xC0000022L – 2012-02-09T14:12:11.477

3

As I recall, Mint is based on Ubuntu, so you should be able to check apt-cache policy apache2:

$ apt-cache policy apache2
apache2:
  Installed: (none)
  Candidate: 2.2.20-1ubuntu1.1
  Version table:
     2.2.20-1ubuntu1.1 0
        500 http://us.archive.ubuntu.com/ubuntu/ oneiric-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu/ oneiric-security/main amd64 Packages
     2.2.20-1ubuntu1 0
        500 http://us.archive.ubuntu.com/ubuntu/ oneiric/main amd64 Packages

In this case, you can see it's not installed on my system. If you haven't asked for it to be installed, it's probably not -- I doubt it's part of the default distribution.

FatalError

Posted 2012-02-09T14:03:19.260

Reputation: 1 913

0

Try this bash command:

if [[ -z $(apache2 -v 2>/dev/null) ]] && [[ -z $(httpd -v 2>/dev/null) ]]; then echo "Apache not found"; fi

Zyx Rhythm

Posted 2012-02-09T14:03:19.260

Reputation: 1

0

As root, you can test if apache is running under process name httpd, apache, or apache2, using

ps -A | grep 'apache\|httpd'

But again, this will only find apache if the process is running.

siliconrockstar

Posted 2012-02-09T14:03:19.260

Reputation: 211

1If works even if you are not root. – Hastur – 2015-04-24T17:17:03.953

Ah cool, wasn't sure if non-privileged users could list global processes, thanks. – siliconrockstar – 2015-04-25T02:31:31.247