13

I've just taken over webmastery for my company's site, and I'm preparing a report for my partner about the LAMP stack. But I'm a new CS graduate, and the only thing I know really well is Java coding, so I need some help!

I'm trying to find out a) if Apache is installed and b) what version is running.

My Linux version is "Ubuntu 8.04.4 LTS \n \l", as reported by /etc/issue.

Iain Samuel McLean Elder
  • 1,232
  • 4
  • 15
  • 27

7 Answers7

19

Is it running?

pgrep apache

Any output is good, nothing means it isn't running.

What version:

aptitude show apache2
wzzrd
  • 10,409
  • 2
  • 35
  • 47
4

Have you tried talking to it?

telnet localhost 80
HEAD / HTTP/1.0
<extra carriage return>
Gerald Combs
  • 6,441
  • 25
  • 35
  • `telnet localhost 80` produces `-bash: telnet: command not found` – Iain Samuel McLean Elder Sep 03 '10 at 22:10
  • You should consider installing it or something with similar functionality such as ncat (part of nmap 5). Talking directly to your web (or SMTP or POP or IMAP or SIP or FTP or …) server can be indispensable for troubleshooting. – Gerald Combs Sep 07 '10 at 15:28
3

To check for Apache 1.X see below, for Apache 2.X see wzzrd's answer.

The apache web server process is called httpd so a quick way to start with confirming apache is installed and running is:

ps -A | grep 'httpd'

ps -A lists all the running processes grep 'httpd' filters only lines containing 'httpd'

If you don't get any results, apache is not running.

regarding version, try:

apachectl status

in the output there should be a line like:
Apache/1.3.41 Server at www.xyz.com Port 80

If it cannot find apachectl, it may not be in your execution path, try:
whereis apachectl
to see where it is located

These are distribution agnostic ways so no matter how apache was installed on the system, you should find it with these.

ManiacZX
  • 1,656
  • 13
  • 16
0

Newer Ubuntu versions use systemd, which means you can use the command systemctl for this purpose:

$ systemctl is-active apache2
active

If you don't need the output, but want to use the status in an if statement in a shell script, you can use the --quiet option, like this:

if systemctl is-active --quiet apache2 ; then
   echo "apache2 is running"
else
   echo "apache2 is not running"
fi

Reference:

Flimm
  • 460
  • 5
  • 16
0
/sbin/service httpd status

Will say that you don't have it | it's OK | it's OFF

Novikov
  • 121
  • 1
0

Click here: http://localhost If you don't get an error 404, it's running.

cfischer
  • 292
  • 1
  • 4
  • 9
  • My server instance is a VPS, so I can't just click a link on my local machine to check whether it's running. – Iain Samuel McLean Elder Sep 04 '10 at 02:12
  • You could run some ncurses web browser like links or lynx directly on the server. – halp Sep 04 '10 at 03:48
  • There are many reasons why http://localhost might not give a 404 error . For example, another server may be running. Also, it's possible for Apache to return a 404 error when it is running. – Flimm Jul 07 '23 at 21:04
0

For Apache/2.2.22 you can also try. It will show you a few processes.

ps -A | grep 'apache'
user1641443
  • 103
  • 1
  • 4