Linux Troubleshooting Bible [Electronic resources]

Christopher Negusand, Thomas Weeks

نسخه متنی -صفحه : 213/ 145
نمايش فراداده

Common Apache Usage

As an alternative to using

redhat-config-httpd to configure and control Apache, we recommend that you still edit the

httpd.conf file by hand and use command-line instructions to control the Apache httpd service. Table 17-1 shows some common Apache management commands based on the SysV initialization scripts now common across many Linux distributions.

Table 17-1: Common Apache Commands

Command

Action

/etc/init.d/httpd start

Start the web daemon

/etc/init.d/httpd stop

Stop the web daemon

/etc/init.d/httpd restart

Stop the daemon and then start it quickly

/etc/init.d/httpd reload

Reload the configuration files (safer and faster to use if no IP binding changes have been made)

/etc/init.d/httpd status

Obtain the daemon status

/etc/init.d/httpd -help

Obtain a listing of init script options

/etc/init.d/httpd configtest

Test your Apache configuration file changes before reloading/restarting

Note

These commands call daemon initialization scripts that are actually located in the

/etc/rc.d/init.d/ directory. A shortcut (symlink) to this directory is

/etc/init.d/ . As listed here, the commands are invoked with the shorthand absolute path of

/etc/init.d/httpd instead of

/etc/rc.d/init.d/httpd .

Note

The

service httpd start and

/etc/init.d/httpd start forms are equivalent. The format you use is entirely a matter of preference, but the former is a Red Hat standard. Many administrators prefer the latter form because they're used to it and because they can use tab completion to "remember" the name of a given daemon.

Once you have configured Apache to behave in the way you prefer, added your websites, and used the

configtest command to verify you don't have any typos, you can use the

chkconfig command to define the run levels in which Apache (or httpd) will start (and thus at boot time also). When you first look at Apache's run level settings with

chkconfig , you see this:

# chkconfig --list httpd
httpd   0:off   1:off   2:off   3:off   4:off   5:off   6:off

This means that

Apache/httpd is not configured to start in any run level at boot time, including the typical default runlevels of either 3 or 5 (in Red Hat-based distros). So in short, httpd will not automatically come up with these settings.

To add

httpd to all of its default run levels (in Red Hat or Fedora Core Linux), simply tell

chkconfig to add it for you:

# chkconfig httpd on

If you check again, you'll now see

httpd included in runlevels 2 through 5:

# chkconfig --list httpd
httpd   0:off  1:off   2:on   3:on   4:on   5:on   6:off

Or, you could have also configured it to come up at specific runlevels like this:

# chkconfig --level 35 httpd on
# chkconfig --list httpd
httpd    0:off  1:off   2:off   3:on   4:off   5:on   6:off

Now that the run levels are configured, you can start Apache and check to see that it's running:

# /etc/init.d/httpd status
httpd is stopped
# /etc/init.d/httpd start
Starting httpd:                                      [  OK  ]
# /etc/init.d/httpd status
httpd (pid 5653 5652 5651 5650 5649 5648 5647 5646 5643) is running...

Tip

Always remember to check that your production services or daemons are set up to run in the appropriate run levels. When web and e-mail administrators look to see why a service or daemon has stopped responding, or to restart said daemon, they sometimes forget to see if the daemon boot time configuration, or init script settings, are configured correctly via

chkconfig . Even if you fix what originally crashed the daemon, you may have the same problem the next time the machine is rebooted or changes run levels if you do not verify that it is set to come back up. If you use

chkconfig as shown earlier, you can be sure that the service will come up after any system state change.