If you installed Linux as suggested in Chapter 2, Apache should be running when you start your machine. To check, load this URL in your browser:
You should see the Apache welcome page, as shown in Figure 3.2. If not, Apache may not be running. Not a major crisis ”in fact, it's a good thing if daemons such as Apache don't run unless you explicitly start them. If Apache has been running since you booted and plugged in the TCP/IP connection, other services are probably running, and you should configure them as you wish, firewall them, or turn them off (see [Hatch+ 02]). To check whether Apache is running, try the following:
Figure 3.2. Apache welcome page
# ps ax grep httpd
Although the program is called Apache, the daemon's name is httpd on Red Hat, apache on some others. You should see something like this:
1922 ? S 0:00 /usr/sbin/httpd 1927 ? S 0:00 /usr/sbin/httpd 1928 ? S 0:00 /usr/sbin/httpd 1929 ? S 0:00 /usr/sbin/httpd 1930 ? S 0:00 /usr/sbin/httpd 1932 ? S 0:00 /usr/sbin/httpd 1933 ? S 0:00 /usr/sbin/httpd 1935 ? S 0:00 /usr/sbin/httpd 1937 ? S 0:00 /usr/sbin/httpd
Several copies of the server are running, so Apache can process more than one request at a time.
If you don't see a number of httpd PIDs, start the server as follows :
# /etc/init.d/httpd start
In addition to using the ps command, you can check the status of your server by executing the following command:
# /etc/init.d/httpd status
The output of this command should resemble this: 
httpd (pid 1937 1935 1933 1932 1930 1929 1928 1927 1922) is running...
If you didn't get this sort of result, or you got an error message, review the logs in /var/log/httpd for error messages, specifically error_log , and read the man page ( man httpd , not man apache ). Unfortunately, the number of possible errors is great, and we can't possibly cover all of them ”the logs are key to narrowing down the problem.
If httpd is running, and you didn't see the welcome page when you loaded http://localhost/ , you have a problem.
First, try restarting it. There are several ways to do this ”the easiest is to use the provided start-up script:
# /etc/init.d/httpd stop # /etc/init.d/httpd start
Also good to know is this:
# /etc/init.d/httpd help
The option help is not a defined option, but if you pass an invalid option to /etc/init.d/httpd , it will tell you all the valid ones.
You can also do this ”it sends the USR1 signal to all occurrences of httpd , making the daemon reload the configuration file:
# /etc/init.d/httpd graceful
# killall -USR1 httpd
Killall may not be installed on your system. If it isn't, consider finding it and installing it; it's invaluable. It saves the step of finding the process ID and passing that to the kill command. The parameter USR1 ( man kill and man signal ) is the graceful way to reload a process ”it allows the process and its children to exit after serving existing requests before starting again. If all else fails, there's always kill -9 .
The gentlest way to restart apache is to use the graceful option to the start-up script. Therefore, hereafter when we need to restart the server (usually to reread the configuration file), we will execute the following command:
# /etc/init.d/httpd graceful
If all this doesn't work, you may need to adopt sterner measures. See the Apache documents at httpd.apache.org/docs/. The Linux Documentation Project at www.linuxdoc.org/ is another excellent place to waste a few hours. Another excellent way to figure out how to fix errors, or to find a support group to commiserate with, is to paste the error ( enclosed in quotes) into Google or Google's group interface.
Once you have Apache running, make sure it starts at boot. Execute chkconfig :
# chkconfig --list httpd httpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
If you do not see output indicating that 3, 4, and 5 are on , turn them on:
# chkconfig httpd on # chkconfig --list httpd httpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
Next time you reboot the machine ( shutdown -r now as root or with sudo ), check that httpd starts with ps or /etc/init.d/httpd status .