Red Hat Linux 7 Unleashed

Red Hat Linux 7 Unleashed

By William Ball

Starting and Stopping the Server

At this point, you have your Apache server installed and configured the way you want it. It's time to start it up for the first time.

Starting the Server Manually

The Apache server, httpd, has a few command-line options you can use to set some defaults specifying where httpd will read its configuration directives. The Apache httpd executable understands the following options:

httpd [-D name][-d directory] [-f file]
             [-C "directive"] [-c "directive"]
             [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T]

The -D option defines a name for use with <IfDefine name> directives in your configuration files. This allows you to conditionally include or exclude sections of your configuration when starting the server.

The -d option overrides the location of the ServerRoot directory. It sets the initial value of the ServerRoot variable (the directory where the Apache server is installed) to whichever path you specify. This default is usually read from the ServerRoot directive in httpd.conf.

The -f flag specifies the location of the main configuration file, conf/httpd.conf. It reads and executes the configuration commands found in ConfigurationFile on startup. If the ConfigurationFile is not an absolute path (it doesn't begin with a /), its location is assumed to be relative to the path specified in the ServerRoot directive in httpd.conf. By default, this value is set to ServerRoot /conf/httpd.conf.

The -v option prints the development version of the Apache server and terminates the process.

The -V option shows all of the settings that were in effect when the server was compiled.

The -h option prints the following usage information for the server:

Usage: httpd [-D name] [-d directory] [-f file]
                       [-C "directive"] [-c "directive"]
                       [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-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
  -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
  -S               : show parsed settings (currently only vhost settings)
  -t               : run syntax check for config files (with docroot check)
  -T               : run syntax check for config files (without docroot check)

The -l option lists those modules that are compiled into your Apache server.

The -L option lists all of the configuration directives that are available with the modules that are compiled into your Apache server.

The -S option lists the virtual host settings for the server.

The -t option is extremely useful. It runs a syntax check on your configuration files. It's a good idea to run this check before restarting your server, once you have made changes to your configuration files. Performing such a test is especially important because an error in the configuration file might result in your server shutting down when you try to restart it.

The -T option is the same as the -t option, but it does not check the configured document roots.

The /etc/rc.d httpd Scripts

Red Hat Linux uses scripts in the /etc/rc.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 and it is shown in Listing 12.2.

You can use the following options to control the Web server:

For example, to check on the current status, use the command

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

which prints the following for me:

httpd (pid 8643 8642 6510 6102 6101 6100 6099 6323 6322 6098 6097 6096  6095 362 6094 6093) is running...

This indicates that the Web server is running; in fact, there are 16 instances of the server currently running.

Example 12.2. /etc/rc.d/init.d/http

#!/bin/sh
#
# Startup script for the Apache Web Server
#
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server.  It is used to serve #               HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /etc/httpd/conf/access.conf

# config: /etc/httpd/conf/httpd.conf
# config: /etc/httpd/conf/srm.conf


# Source function library.
. /etc/rc.d/init.d/functions

# See how we were called.
case "$1" in
  start)
        echo -n "Starting httpd: "
        daemon httpd
        echo
        touch /var/lock/subsys/httpd
        ;;
  stop)
        echo -n "Shutting down http: "
        killproc httpd
        echo
        rm -f /var/lock/subsys/httpd
        rm -f /var/run/httpd.pid
        ;;
  status)
        status httpd
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  reload)
        echo -n "Reloading httpd: "
        killproc httpd -HUP
        echo
        ;;
  *)
        echo "Usage: $0 { start|stop|restart|reload|status} "
        exit 1
esac

exit 0
					
					
					
					
				

Share ThisShare This

Informit Network