Flylib.com

Books Software

 
 
 

Configuration File Basics


Configuration File Basics

The following table provides the default location of the main Apache configuration file on multiple operating systems. Notice that since versions 1.3 and 2 of the server may need to coexist side by side, the name of the file may be different for each version.

Table 1.1. The Location of httpd.conf on Different Systems

Configuration File Location

Platform

/etc/httpd/httpd.conf
/etc/httpd/httpd2.conf

Suse, Mandrake, older
Red Hat systems

/etc/httpd/conf/httpd.conf
/etc/httpd/conf/httpd2.conf

Newer Red systems, Fedora Core

/usr/local/apache2/conf
/usr/local/apache/conf

When compiling from source as explained earlier in this chapter

c:\Program Files\Apache Group \Apache2\conf\httpd.conf

Windows

c:\Program Files\Apache Group\Apache2\conf\httpd.conf

 

/private/etc/httpd/httpd.conf

Mac OS X


The main Apache configuration file is called httpd.conf. The location of this file varies depending on whether you are using Windows or Linux, and whether you compiled Apache from source code or used the binary provided by your distribution. Check the locations suggested in the previous table.

Apache uses plain text files for configuration. The configuration files can contain directives and containers (also known as "sections"). You can place comments inside the file by placing a hash mark (#) at the beginning of a line. Comment lines will be ignored by Apache. A directive can span several lines if you end the previous line with a backslash character (\).

Directives control every aspect of the server. You can place directives inside containers, so they only apply to content served from a certain directory or location, requests served by a particular virtual host, and so on.

When an argument to a directive is a relative path, it is assumed to be relative to the server installation path (server root). For example, if you installed Apache from source as described earlier in this chapter, the server root is /usr/local/apache or /usr/local/apache2 . You can change the default with the ServerRoot directive.



Using Multiple Configuration Files


Include /etc/httpd/conf/perl.conf


Include conf.d/*.conf


Include siteconf/


It is sometimes useful to split the server configuration into multiple files. The Include directive allows you to include individual files, all of the files in a particular directory, or files matching a certain pattern, as shown in these examples. If a relative path is specified, then it will be considered relative to the path specified by the ServerRoot directive.

This is usually done by Linux distributions that distribute Apache modules as RPMs. Each one of those packages can place its own configuration file in a specific directory, and Apache will automatically pick it up.



Starting, Stopping, and Restarting Apache


apachectl start


apachectl stop


apachectl restart


apachectl graceful


To start, stop, or restart Apache, you can issue any of these commands. Depending on how you installed Apache, you may need to provide an absolute path to apachectl , such as /usr/sbin/apachectl or /usr/local/apache/bin/apachectl . Although it is possible to control Apache on Unix using the httpd binary directly, it is recommended that you use the apachectl tool. The apachectl support program is distributed as part of Apache and wraps common functionality in an easy-to-use script.

On Unix, if Apache binds to a privileged port (those between 11024), you will need root privileges to start the server.

If you make some changes to the configuration files and you want them to take effect, it is necessary to signal Apache that the configuration has changed. You can do this by stopping and starting the server, by sending a restart signal, or by performing a graceful restart. This tells Apache to reread its configuration. To learn the difference between a regular restart and a graceful restart, please read the next section.

As an alternative to using the apachectl script, you can use the kill command directly to send signals to the parent Apache process. This is explained in detail in the "Alternate Ways of Stopping Apache" section in Chapter 2.

On Windows, you can signal Apache directly using the apache.exe executable:

apache.exe -k restart
apache.exe -k graceful
apache.exe -k stop


You can access shortcuts to these commands in the Start menu entries that the Apache installer created. If you installed Apache as a service, you can start or stop Apache by using the service management tools in Windows as follows : In Control Panel, select Administrative Tasks, and then click on the Services icon.

Additionally, Apache 2.0 can place a program, Apache Monitor, in the system tray. It is a simple GUI that you can use to start and stop the server directly or as a service. It is either installed at startup or you can launch it from the Apache entry in the Start menu.

What Is a Graceful Restart?

A "regular" restart stops the Apache server and starts it again. As a result, current requests are aborted and no new requests are served until the server is up and running again. Therefore, a normal restart can result in a momentary pause of service .

A graceful restart takes a different approach. Each thread or process serving a client will keep processing the current request, but when it is finished, it will be killed and replaced by a new thread or process with the new configuration. This allows seamless operation of the web server with no downtime .

The most practical way of performing a graceful restart in Unix is issuing the following command:

# apachectl graceful


In Windows, use

Apache.exe -k graceful