Выбрать главу

Files are placed in various subdirectories of /usr/local/apache (or whatever directory you specified with the --prefix parameter) if you build the server from source.

The following is a list of the directories used by Apache, as well as brief comments on their usage:

► /usr/local/apache/conf — This contains several subdirectories and the Apache configuration file, httpd.conf. See the "Editing httpd.conf" section, later in this chapter, to learn more about configuration files.

► /usr/local/apache — The cgi-bin, icons, and htdocs subdirectories contain the CGI programs, standard icons, and default HTML documents, respectively.

► /usr/local/apache/bin — The executable programs are placed in this directory.

► /usr/local/apache/logs — The server log files are placed in this directory. By default, there are two log files — access_log and error_log — but you can define any number of custom logs containing a variety of information (see the "Logging" section later in this chapter). The default location for Apache's logs as installed by Fedora is /var/log/httpd.

A Quick Guide to Getting Started with Apache

Setting up, testing a web page, and starting Apache with Fedora can be accomplished in just a few steps. First, make sure that Apache is installed on your system. Either select it during installation or install the server and related RPM files.

Next, set up a home page for your system by editing (as root) the file named index.html under the /var/http/www/html directory on your system. Make a backup copy of the original page or www directory before you begin so that you can restore your web server to its default state if necessary.

Start Apache (again, as root) by using the service command with the keywords httpd and start, like this:

# service httpd start

You can also use the httpd script under the /etc/rc.d/init.d/ directory, like this:

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

You can then check your home page by running a favorite browser and using localhost, your system's hostname, or its Internet Protocol (IP) address in the URL. For example, with the links text browser, use a command line like this:

# links http://localhost/

For security reasons, you shouldn't start and run Apache as root if your host is connected to the Internet or a company intranet. Fortunately, Apache is set to run as the user and group apache no matter how it's started (by the User and Group settings in /etc/httpd/httpd.conf). Despite this safe default, Apache should be started and managed by the user named apache, defined in /etc/passwd as:

apache:x:48:48:Apache:/var/www:/sbin/nologin

After you are satisfied with your website, use the setup (select Services) or ntsysv (select httpd) command to ensure that Apache is started properly.

Starting and Stopping Apache

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 11, "Automating Tasks," for more information about how Fedora boots.

It is time to start Apache up for the first time. The following sections show how to 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 shut ting 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 super- user can bind to Internet ports that are lower than 1024.