Apache Basics, Visited / Page 2 | WebReference

Apache Basics, Visited / Page 2


[previous] [next]

Apache Basics, Visited [con't]

Stop The Apache Server

Stopping your Apache installation is an easy affair, but it's one that must be covered in order for you to work with Apache in the future. The below example shows how to stop the Apache server on a Linux system.

This example assumes you're within the working Apache directory. If you aren't, you would use the entire path to the apachectl executable.

Restart The Apache Server, Gracefully

There are several ways to restart your server. You can use a command line directive or you can use the operating system to stop the Apache process. You would then have to restart according to the procedure given in an earlier section of this document. Examine the following:

A graceful restart will restart the server after all waiting server calls have completed. The server then restarts and accepts new calls. This has the benefit of completing the waiting calls to the server before restarting. You would normally restart in this fashion after a configuration change within your httpd.conf file.

Review Run-time Configuration Directives

Run-time configuration directives are the commands and configuration notes that Apache uses to start the server. There are perhaps 200 of these directives, so a full explanation of these directives is beyond the scope of this article. See the manual that comes with the Apache distribution on the CD-ROM for a detailed explanation of every run-time configuration directive.

There are eight general types of runtime directives. They are server config, virtual host, directory, .htaccess, Core, MPM (Multi-Processing Modules), Base, Extension and Experimental. Each of these run-time configuration types are an integral part of your Apache server's configuration, and are read at server startup time.

The configuration directives are grouped into three basic sections within the httpd.conf file:

  1. Directives that control the operation of the Apache server process as a whole (the 'global environment').
  2. Directives that define the parameters of the 'main' or 'default' server, which responds to requests that aren't handled by a virtual host. These directives also provide default values for the settings of all virtual hosts.
  3. Settings for virtual hosts, which allow Web requests to be sent to different IP addresses or hostnames and have them handled by the same Apache server process.

You'll get a feeling for what each type of directive does with further use of the server and after reading the Apache manual.

Set The Server Root

The server root is the place where the Apache executable and configuration files are stored on the local machine. For example:

The ServerRoot directive tells the Apache server where the Web site documents, executables and configuration files start.

Set The Server Name

The server name is the domain name to serve Apache files. You may specify a domain name or an IP address as the server name attribute.

The ServerName directive tells the Apache server what the URL of the server is to be. If you are using Apache as a developer server on your own desktop computer, use a server name of "127.0.0.1". This is the local loop back address and will allow you to serve pages from your own machine.

Set The Document Root

The document root is the location of the directory that will be serving the pages for your Web site. It is given as a file system location. The example below is a document root as given on a Windows machine.

The DocumentRoot directive tells the server where to find the HTML files that will be served, and is a reflection of your file system. It's also is used to show the general location of the CGI-BIN for PERL scripts.

Set The CGI-BIN Location

In order to use PERL with your Apache installation, PERL will have to be installed on the local machine. The CGI-BIN location shows the location of the PERL scripts that your Apache server will be serving.

ScriptAlias /cgi-bin/ "C:\apache\htdocs\cgi-bin\"

The example sets the ScriptAlias location. This tells the server where to expect CGI scripts. Your ScriptAlias doesn't need to be within the document or server root – you can have it anywhere on the local machine, on any operating system supported.

You may specify the location and name of your CGI-BIN as something other than the norm. Apache has provided this functionality for those server setups that don't conform to this norm. Using a setup in this manner isn't the norm, but can be a fun way to personalize yourWeb site. You don't even have to have your CGI scripts end with the .cgi or .pl extension. You can use something descriptive to conform to your site's theme. Simply use the knowledge in the coming pages to change the Apache directives to conform to your theme.

What you would do is alter the default settings within your httpd.conf file, which is the main configuration file that Apache uses at start up to apply the settings you've chosen. These settings don't have to include the default settings – you can specify anything you like. There are several large sites that I've encountered that use a custom setup such as this. They've used the theme of their site to their advantage, adding a customized flair to their configuration files that are reflected in the address bar in the browser.

Understand Apache Modules

Modules are the way that Apache adds functionality. That is, each module does one precise thing, all working together to deliver a very fast and reliable set of server features. The core modules are as follows:

  • core: Core Apache HTTP Server features that are always available
  • mpm_common: A collection of directives that are implemented by more than one multi-processing module (MPM)
  • beos: This Multi-Processing Module is optimized for BeOS
  • leader: An experimental variant of the standard worker MPM
  • mpm_netware: Multi-Processing Module implementing an exclusively threaded web server optimized for Novell NetWare
  • mpmt_os2: Hybrid multi-process, multi-threaded MPM for OS/2
  • perchild: Multi-Processing Module allowing for daemon processes serving requests to be assigned a variety of different userids
  • prefork: Implements a non-threaded, pre-forking web server
  • threadpool: Yet another experimental variant of the standard worker MPM
  • mpm_winnt: This Multi-Processing Module is optimized for Windows NT
  • worker: Multi-Processing Module implementing a hybrid multi-threaded multi-process web server

Each of these core modules are required for the server to function. There are perhaps 100 more modules that are available in the source distribution that comes with the Apache installation files, each adding to the functionality of your Apache Web server.

One module in particular we'll be dealing with is mod_perl. mod_perl is a module that was written to increase the speed and functionality of the Perl scripts the server runs. It acts as a compiler, pre-compiling your script for quicker execution. mod_perl has dramatically increased the speed of execution for all Perl scripts by eliminating a step in the execution order. That is, in a typical situation, a Perl script is called and parsed. It is then compiled and executed. Mod_perl eliminates one step in the execution of any Perl script by pre-compiling the script into its immediately executable form, leaving that compiled instance of the script in memory.

Other modules add functionality for administration, user request tracking, and hundreds of other small functions that, together as a whole, add greatly to the functionality of the Apache server. It's entirely possible to write your own modules to be used with your Apache server. This is beyond the scope of this document, but it should be known that if you learn the C programming language, you may write your own modules.

One module that I find to be particularly useful is the mod_speling module, which allows for a user to misspell one letter of an address, yet still have the server respond to that misspelled URL. This has the benefit of reducing user frustration. You might also notice what I can only take as humor in the spelling of the mod_speling module – the word "speling" is misspelled. Let it be known that the developers have a sense of humour.

Now let's concentrate on the core module. The core module, aptly named, contains the core functions for the Apache server. Each of the functions of core has its own use, and we'll explore some of them in detail in the coming sections. Knowing how core works is important in that the most basic functions are represented. There are 62 directives in core, and each can be used within your httpd.conf file. Settings in httpd.conf are parsed during startup or during a restart.

Understanding the core functions will allow greater control of your Apache server. It's recommended that you read and understand each of the core functions, which are explained in exhaustive detail in the manual that comes with Apache. Many of the core functions include a default setting, and many are simply on and off switches, which makes things simple.


[previous] [next]