Starting and Stopping Apache

 < Day Day Up > 

At this point, you have installed your Apache server with its default configuration. Fedora provides a default home page named index.html as a test under the /var/www/html/usage directory. The proper way to run Apache is to set system initialization to have the server run after booting, network configuration, and any firewall configuration. See Chapter 14, "Automating Tasks," for more information about how Fedora boots.

It is time to start it up for the first time. The following sections show how to either start and stop Apache or configure Fedora to start or not start Apache when booting.

Starting the Apache Server Manually

You can start Apache from the command line of a text-based console or X terminal window, and you must have root permission to do so. The server daemon, httpd, recognizes several command-line options you can use to set some defaults, such as specifying where httpd reads its configuration directives. The Apache httpd executable also understands other options that enable you to selectively use parts of its configuration file, specify a different location of the actual server and supporting files, use a different configuration file (perhaps for testing), and save startup errors to a specific log. The -v option causes Apache to print its development version and quit. The -V option shows all the settings that were in effect when the server was compiled.

The -h option prints the following usage information for the server (assuming that you're running the command as root):

 # httpd -h Usage: httpd [-D name] [-d directory] [-f file]              [-C "directive"] [-c "directive"]              [-k start|restart|graceful|stop]              [-v] [-V] [-h] [-l] [-L] [-t] Options:   -D name           : define a name for use in <IfDefine name> directives   -d directory      : specify an alternate initial ServerRoot   -f file           : specify an alternate ServerConfigFile   -C "directive"    : process directive before reading config files   -c "directive"    : process directive after reading config files   -e level          : show startup errors of level (see LogLevel)   -E file           : log startup errors to file   -v                : show version number   -V                : show compile settings   -h                : list available command line options (this page)   -l                : list compiled in modules   -L                : list available configuration directives   -t -D DUMP_VHOSTS : show parsed settings (currently only vhost settings) -t                : run syntax check for config files 

Other options include listing Apache's static modules, or special, built-in independent parts of the server, along with options that can be used with the modules. These options are called configuration directives and are commands that control how a static module works. Note that Apache also includes nearly 50 dynamic modules, or software portions of the server that can be optionally loaded and used while the server is running.

The -t option is used to check your configuration files. It's a good idea to run this check before restarting your server, especially if you've made changes to your configuration files. Such tests are important because a configuration file error can result in your server shutting down when you try to restart it.

NOTE

When you build and install Apache from source and don't use Fedora's Apache RPM files, start the server manually from the command line as root (such as when testing). You do this for two reasons:

  • The standalone server uses the default HTTP port (port 80), and only the superuser can bind to Internet ports that are lower than 1024.

  • Only processes owned by root can change their UID and GID as specified by Apache's User and Group directives. If you start the server under another UID, it runs with the permissions of the user starting the process.

Note that although some of the following examples show how to start the server as root, you should do so only for testing after building and installing Apache. Fedora is set up to run web service as the apache user if you install Apache using Fedora RPM files.


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

Fedora uses the scripts in the /etc/rc.d/init.d directory to control the startup and shutdown of various services, including the Apache web server. The main script installed for the Apache web server is /etc/rc.d/init.d/httpd, although the actual work is done by the apachectl shell script included with Apache.

NOTE

/etc/rc.d/init.d/httpd is a shell script and isn't the same as the Apache server located in /usr/sbin. That is, /usr/sbin/httpd is the program executable file (the server); /etc/rc.d/init.d/httpd is a shell script that uses another shell script, apachectl, to control the server. See Chapter 14 for a description of some service scripts under /etc/rc.d/init.d and how the scripts are used to manage services such as httpd.


You can use the /etc/rc.d/init.d/httpd script and the following options to control the web server:

  • start The system uses this option to start the web server during bootup. You, as root, can also use this script to start the server.

  • stop The system uses this option to stop the server gracefully. You should use this script, rather than the kill command, to stop the server.

  • reload You can use this option to send the HUP signal to the httpd server to have it reread the configuration files after modification.

  • restart This option is a convenient way to stop and then immediately start the web server. If the httpd server isn't running, it is started.

  • condrestart The same as the restart parameter, except that it restarts the httpd server only if it's actually running.

  • status This option indicates whether the server is running; if it is, it provides the various PIDs for each instance of the server.

For example, to check on the status of your server, use the command

 # /etc/rc.d/init.d/httpd status 

This prints the following for me:

 httpd (pid 15997 1791 1790 1789 1788 1787 1786 1785 1784 1781) is running... 

This indicates that the web server is running; in fact, 10 instances of the server are currently running in this configuration.

In addition to the previous options, the httpd script also offers these features:

  • help Prints a list of valid options to the httpd script (which are passed onto the server as if called from the command line).

  • configtest A simple test of the server's configuration, which reports Status OK if the setup is correct. You can also use httpd's -t option to perform the same test, like this:

     # httpd -t 

  • fullstatus Displays a verbose status report.

  • graceful The same as the restart parameter, except that the configtest option is used first and open connections are not aborted.

TIP

Use the reload option if you're making many changes to the various server configuration files. This saves time when you're stopping and starting the server by having the system simply reread the configuration files.


Controlling Apache with Red Hat's service Command

Instead of directly calling the /etc/rc.d/init.d/httpd script, you can use Red Hat's service command to start, stop, and restart Apache. The service command is used with the name of a service (listed under /etc/rc.d/init.d) and an optional keyword:

 # service <name_of_script> <option> 

For example, you can use service with httpd and any option discussed in the previous section, like so:

 # service httpd restart 

This restarts Apache if it's running or starts the server if it isn't running.

Controlling Apache with Red Hat's chkconfig Command

The chkconfig command provides a command-line based interface to Fedora's service scripts. The command can be used to list and control which software services will be started, restarted, and stopped for a specific system state (such as when booting up, restarting, or shutting down) and runlevel (such as single-user mode, networking with multitasking, or graphical login with X).

For example, to view your system's current settings, take a look at Fedora's default runlevel as defined in the system initialization table /etc/inittab using the grep command:

 # grep id: /etc/inittab id:3:initdefault: 

This example shows that this Fedora system will boot to a text-based login without running X11. You can then use the chkconfig command to look at the behavior of Apache for that runlevel:

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

Here you can see that Apache is turned off for runlevels 3 and 5 (the only two practical runlevels in a default Fedora system, although you could create a custom runlevel 4 for Apache). Use --level, httpd, and the control keyword on to set Apache to automatically start when booting to runlevel 3:

 # chkconfig --level 3 httpd on 

You can then again use chkconfig to verify this setting:

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

To have Apache also start when your system is booted to a graphical login using X, again use level, httpd, and the control keyword on, but this time, specify runlevel 5 like so:

 # chkconfig --level 5 httpd on 

Again, to verify your system settings, use

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

Use the off keyword to stop Apache from starting at a particular runlevel.

Controlling Apache with Red Hat's system-config-services Client

You can also use a graphical version of the chkconfig command named system-config-services during an X session to set when Apache is started or stopped and at which runlevel. To start system-config-services, select the Services on the Server Settings menu from your desktop panel's System Settings menu, or type the command in a terminal window like so:

 $ system-config-services & 

After you press Enter, you're prompted for the root password (because you shouldn't be running X as root).

NOTE

You can also use the ntsysv command to set Apache to start at boot time or start system-config-services using the serviceconf command.


This client is a graphical runlevel editor. To have Apache start when using runlevel 3, first use the Edit Runlevel menu to select runlevel 3 and then scroll through the list of services to find httpd. If you click the httpd check box, as shown in Figure 19.1, and then click the toolbar's Save button, Apache is started at that runlevel the next time the system starts or reboots.

Figure 19.1. Use the system-config-services client to set when Apache is started or stopped on your Fedora system.


You can also use the Service Configuration client to instantly control a service. Use the Edit Runlevel menu to select the current runlevel in use; highlight httpd; and then click the Start, Stop, or Restart toolbar button.

     < Day Day Up > 


    Red Hat Fedora 4 Unleashed
    Red Hat Fedora 4 Unleashed
    ISBN: 0672327929
    EAN: 2147483647
    Year: 2006
    Pages: 361

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net