Apache at your Web Service
You are here: irt.org | Articles | Linux & Apache | Apache at your Web Service
Published on: Sunday 1st August 1999 By: Pankaj Kamthan
Introduction
Apache
began its life in 1995 as an enhanced version of the
NCSA Web server
through a series of "patches" and the result was an
APATCHY server. Over the years
Apache diverged from the original as many features were added to
it. The main legacy in it are the configuration files, which have been
kept for backward compatibility with the NCSA Web Server.
Since its inception, Apache has reached many landmarks. In 1997,
Apache ports for Windows 95 and NT platforms were announced. In 1998,
IBM announced support for the Apache project and a version of Apache
is planned in its Internet commerce servers.
A detailed account of how Apache came about is available at
www.apache.org.
The current distributed version is 1.3.x, and forms the basis of this
article.
Apache User-Base
The benchmark comparisons provided by
Netcraft surveys
show that the use of Apache has grown steadily over the last five
years, and it is the most popular among the Web servers in use
today. As of July 1998, Apache is run on over 1.2 million Internet
servers.
Figure 1 illustrates the statistics on server
share for the period August 1995 - May 1999. You may notice the
(horizontal) symmetry indicating the rise of Apache and corresponding
decline of NCSA over this period of time.
Figure 1. Netcraft Survey on Server Share.
Features of Apache
A comparison of features of a large number of Web servers currently in
use is available at
WebServer Compare.
A quick overview of features of Apache is available at
webcompare.internet.com.
A review of Apache by Server Watch is available at
serverwatch.internet.com.
Advantages of Apache
Apache offers various advantages to users, developers and Web
administrators:
- Features. Apache has various useful
features,
including implementation of the latest protocols.
- Customizable. Apache's modular architecture
allows you to build a server that is
"made to measure."
- Administration. Apache configuration files are in
ASCII, have a simple format, and can be edited using any text
editor. They are transferable, so one can effectively clone a
server. One can control the server from command line, which makes
remote administration very convenient.
- Extensible. Apache server and API source code are
open to public. If there is any feature that you want but does not
exist in Apache, you can write your own server module to implement
it.
- Efficient. A lot of effort has been put into
optimizing the Apache's C code for performance. As a result, it runs
faster and consumes less systems resources than many other
servers.
- Portability. Apache runs on a wide variety of
operating systems, including all variants of UNIX, Windows 9x/NT,
MacOS (on PowerPC), and various others.
- Stability/Reliability. Apache's source code is
open to public. When any bugs are found, they are often quickly
communicated, and rapidly fixed. Updates are made and announced
thereafter. This has resulted in Apache becoming more and more stable,
and hence reliable, server over the time.
- Support. Apache is supported by the Apache Group,
a large number of dedicated users (many of whom can often be found in
the Usenet newsgroup
comp.infosystems.www.servers.unix
or
comp.infosystems.www.servers.ms-windows),
and by companies who market commercial versions of Apache.
Obtaining Apache
Apache is available as
source
as well as in
binary
formats for various operating systems. These sites list the current
release, as well as, recent beta releases. Current distributed version
is 1.3.6. Apache is mirrored world-wide. The best way to download
Apache is to
find the mirror closest to you.
Binary Vs. Source
There is an inherent trade-off between installing a binary and
(compiling and) installing a source. A binary, although easier to
install, may not necessarily be optimized for your system. A source is
relatively more time consuming and difficult to install, as one has to
follow a series of steps and make sure that appropriate versions of
compilers are available on the system. However, the advantage of that
is one can much better customize the server according one's needs.
Apache on Specific Operating Systems
In this section, we will give the details of compiling, installing and
running Apache on UNIX and Windows, and briefly discuss the Apache
port for Macintoshes.
UNIX
By UNIX, we will mean UNIX and its variants, including Linux. All
Apache administration on UNIX is command-line based.
Compiling Apache on UNIX
Change into the src directory of the Apache
distribution. Compiling Apache consists of the following three steps:
- Select modules to compile into Apache in the
Configuration file. A detailed account of the
significance of Apache modules and their customization is given in
Made to Measure : Apache Web Server Customization.
- Configure Apache for your operating system. Run the
Configure script. This generates a Makefile
for use in step 3. (If this fails or you have any special
requirements, you might need to edit one or more of the following
options in the Configuration file: EXTRA_CFLAGS,
LIBS, LDFLAGS, INCLUDES.)
- Type
make.
You should now have a binary file called httpd in the
src directory. A binary distribution of Apache will
supply this file.
Installing Apache on UNIX
Once you have the Apache binary, either as a result of compilation or
from download, the next step is to install the program and configure
it. Apache is designed to be configured and run from the same set of
directories where it is compiled. We now focus our attention to
editing the configuration files for the server.
Configuring Apache on UNIX
There are three central configuration files which contain various
directives that need to be set up. By default, these files are located
in the conf directory and are called
srm.conf, access.conf and
httpd.conf. The names of these files are taken to be
relative to the server root which is set by the
ServerRoot
directive, the -d command line flag, or (on Windows only)
the registry. The files include helpful comments and description
of the directives. These files should be edited with care; failure to
set up these files correctly could lead to the server not working or
being insecure. They could be edited in the following order:
httpd.conf. This file contains
directives that control the operation of the server daemon. It sets up
general attributes about the server: the port number, the user it runs
as, and so on.
srm.conf. This file contains
directives that control the specification of documents that the server
can provide to clients. This sets up the root of the document tree,
special functions like server-parsed HTML or internal imagemap
parsing, etc.
access.conf. This file contains
directives that control access to documents.
The server also reads a file mime.types containing MIME
document types. All these file names can be overridden by appropriate
directives.
Running Apache on UNIX
On UNIX, the httpd program is usually run as a (HTTP)
daemon which executes continuously, handling requests.
Starting the Server
To start the server, simply run httpd. This will look for
httpd.conf in the location compiled into the code (by
default /usr/local/apache/conf/httpd.conf). If this file
is somewhere else, you can give the real location with the -f
option. For example:
/usr/local/apache/httpd -f /usr/local/apache/conf/httpd.conf
If all goes well, this will return to the command prompt almost
immediately which indicates that the server is now up and running. If
anything goes wrong during the initialization of the server, you will
see an error message on the screen.
If the server started properly, you can now use your browser to
connect to the server. Once Apache starts running, it listens to port
80 (unless you changed the Port, Listen or
BindAddress directives in the configuration files). To
connect to the server, start a browser (on the same machine as the
server) and enter the URL:
http://localhost/
or if your host isn't connected to the Internet:
http://127.0.0.1/
This should respond with a "test page" as shown in Figure 2, which is a sign of successful
installation.
Figure 2. Apache Test Page.
When the server starts, it will create a number of child processes to
handle the requests. If you started Apache as the root user, the
parent process will continue to run as root while the children will
change to the user as given in thehttpd.conf file.
If you want your server to continue running after a system reboot, you
should add a call to httpd to your system start-up files
(typically rc.local or a file in an rc.N
directory). This will start Apache as root. Before doing this, ensure
that your server is properly configured for security and access
restrictions. The process ID of this process is written to the file
httpd.pid in the log files
directory logs (unless configured otherwise).
Stopping the Server
A typical command to stop the server is:
kill -TERM `cat /usr/local/apache/logs/httpd.pid`
Restarting the Server
Sending the HUP signal to the parent process causes it to
kill off its children like in TERM but the parent doesn't
exit. It re-reads its configuration files, and re-opens any log files. Then it spawns a new set of children
and continues serving pages.
There is also a script src/support/apachectl which, after
a bit of customization for the system, can be used to start, stop, and
restart Apache.
Linux
Apache comes bundled with, for example, the
RedHat
Linux distribution CD-ROM. It can be installed as a service during the
installation of the operating system itself. The version on the CD,
however, may not always be the latest. The easiest way to upgrade
Apache on Linux to the latest version, is to use the
RPM.
There is an
Apache RPM for Linux
available and is maintained regularly.
To check whether Apache is running on your system, you can type the
URLhttp://localhost/ (or http://127.0.0.1/)
in your browser. For details on the Apache httpd, you can type
ps -ef
on the command line.
Table 1 of the Appendix gives the command line options for administering Apache.
Windows
Apache 1.3 is originally designed to run on Windows NT 4.0. An
installation test was carried out successfully by the author on
Windows 9x and NT 4.0 (Service Pack 4). Note that the binary installer
only works on Intel processors. In all cases, TCP/IP networking is
required.
Compiling Apache on Windows
Compiling Apache requires (at least) Microsoft Visual C++ 5.0 to be
properly installed. We will not discuss the details of the compilation
here.
Installing Apache on Windows
When you run the Apache binary installer, you will be asked
for:
- The directory to install Apache into.
- The Start menu name.
- The installation type. The "Typical" option installs
everything except the source code. The "Minimum" option does
not install the manuals or source code. Choose the "Custom"
install if you want to install the source code.
This results in the following (if the default settings as used) to be
attached in the Start menu:
During the installation, Apache will configure the files in the
conf directory for corresponding to the installation
directory. After installing Apache, you should further edit these
files and adapt it to your needs.
Configuring Apache on Windows
Apache is configured using the files in the conf
directory. These are the same as files used to configure the UNIX
version, with a few different directives. The main differences are:
- Apache for Windows is multithreaded. So the process-management directives are different:
- MaxRequestsPerChild.
This controls how many requests a process will serve before
exiting. Since a process serves all the requests at once, it is
recommended that a very high number is used, if this is set. The
recommended default is 0 (the process never exits).
- ThreadsPerChild.
This is the maximum number of connections the server can handle
simultaneously. This should be set to a high number if it is
anticipated that the site will have a lot of traffic. The recommended
default is 50.
- The directives that accept filenames as arguments use
Windows-style file names. However, since Apache uses UNIX-style names
internally, you must use forward slashes. Drive letters can be used;
if omitted, the drive with the Apache executable is assumed.
- Apache for Windows contains the ability to load modules at
runtime, without recompiling the server. When Apache is compiled, it
installs a number of optional modules in the
\Apache\modules directory. To activate these, or other
modules, the
LoadModule
directive must be used.
See the
Apache documentation
for all the available directives.
Running Apache on Windows
On Windows, Apache is usually run as a console application
on Windows 9x, or as a service on Windows NT.
Running Apache on Windows as a Console Application
This option is available for Windows 9x and NT. To run Apache from a
console window, select the Start Apache as console app option
from the Start menu. This will open a console window and
start Apache running inside it. The window will remain active until
you stop Apache. To stop Apache running, either select the
Shutdown Apache console app from the Start menu
or enter Control-C in the Apache window.
Figure 3 shows Apache running on Windows 9x/NT on
console.
Figure 3. Apache running on Windows 9x/NT.
The Start menu icons can provide a simple interface for
administering Apache. In some cases, however, it is easier to work
from the command line.
Table 2
of the
Appendix
gives the command line options for administering Apache.
Running Apache on Windows as a Service
This option is available on Windows NT only. This is the best choice
if you want Apache to automatically start when you boot the machine,
and to keep Apache running when you log off.
To start Apache as a service, you first need to install it as a
service. Multiple Apache services can be installed, each with a
different name and configuration. To install the default Apache
service named "Apache", run the Install Apache as
Service (NT only) option from the Start menu. Once this
is done, you can start the "Apache" service by opening the
Services window (in the Control Panel), selecting Apache,
then clicking on Start. Apache should now be running in the
background. You can later stop Apache by clicking on Stop
from the Services window.
Once Apache starts running (either in a console window or as a
service), it listens to port 80 (unless you changed the
Port, Listen or BindAddress
directives in the configuration files). To connect to the server,
start a browser (on the same machine as the server) and enter the URL:
http://localhost/
or if your host isn't connected to the Internet:
http://127.0.0.1/
This should respond with a "test page" as shown in
Figure 2.
The Start menu icons and the NT Service manager can provide a
simple interface for administering Apache. In some cases, however, it
is easier to work from the command line.
Table 3 of the Appendix
gives the command line options for administering Apache.
Macintosh
WebTen from Tenon Intersystems, is a commercial
Apache-derivative Web server for Power Macintoshes. WebTen has a
browser-based interface and supports standard Macintosh-style
plug-ins, CGI, and SSL. Currently, WebTen for MacOS and
iTools (previously
WebTen v4.0) for MacOS X Server are available.
Log Files
Apache comes equipped with log files (in the logs
directory) which contain information regarding the activity of the
server.
- Process ID Log. When started, Apache saves the
process ID of the parent process in the file
httpd.pid. This process ID can be used for restarting and
terminating the server.
- Error Log. Apache logs error messages in a log
file,
error_log, on UNIX and error.log on
Windows 9x/NT. This file can be used for monitoring server activities,
particularly start-up problems or other failed efforts by the
server.
- Transfer Log. Apache typically logs each request
to a transfer file,
access_log, on UNIX and
access.log, on Windows 9x/NT. This file can be used for
monitoring user access, and gathering basic information about the
user's environment.
All these file names can be overridden by appropriate directives.
Troubleshooting
There are various problems that can occur in getting Apache to
work. They are usually related to system or compiler
incompatibilities, or improper settings in the configuration files.
Compilation Problems
If the server source doesn't compile on your system, it
could be due to any one of the following reasons:
- Operating System Problems. Your operating system
could be incompatible and needs to be upgraded.
- C Compiler Problems. Some operating systems
include a default C compiler that is either not ANSI C-compliant or
suffers from other deficiencies. The recommendation, in such a case,
is to install gcc and compile the server with it. After
any compiler installation/upgrade (or operating system upgrade), you
should make sure that your C header files and include directory tree
are consistent with the compiler (and the operating system).
Installation Problems
If a server binary doesn't install on your system, it could be due to
any one of the following reasons:
- You downloaded a binary incompatible with your system and tried to
install it.
- There are system-specific problems (such as insufficient space or
memory) for which you will get an error response, and you can take
appropriate steps.
Running Problems
- If the server complains about being unable to "bind" to
an address, then either some other process is already using the port
you have configured Apache to use, or the server is running as a
"normal" user but trying to use a port below 1024 (such as
the default port 80).
- If the server is not running at all, then read the error message
displayed when you try to run it and also check the server
error_log (error.log) file for additional
information.
Support
Most problems that get reported to The Apache Group are recorded in
the
bug database
that you can refer to. Another useful resource is the
The Apache FAQ.
Depending on your platform, Usenet newsgroups
comp.infosystems.www.servers.unix
for UNIX and its derivatives or
comp.infosystems.www.servers.ms-windows
for Windows 9x/NT, can be quite helpful if you have
installation/configuration questions. Both are frequently visited by
experienced users and you can usually expect a quick response to your
query.
Limitations of Apache
Even though Apache is an extremely powerful server with a wide
assortment of features, it does have certain, arguably minor, caveats:
- Apache does not provide the GUI-based convenience administration
of configuration files.
- The Macintosh version of Apache (unlike its UNIX or Windows
counterparts) is not freely available.
- Apache (except the Windows NT version) is not multithreaded.
- The Windows versions do not have all the bells and whistles found
in the UNIX versions. For example, it has not yet been optimized for
performance. As the Windows version is being actively pursued, it is
expected that these differences will vanish in future.
Conclusion
The decision of choosing the "right" Web server is crucial
for anybody who intends to have a presence and provide a service on
the Web. Apache, with its numerous features, makes an excellent
choice.
However, it must be said that running a Web server is relatively easy,
but running a well-managed server isn't. A poorly managed server is an
open invitation to a world of problems, which can involve anywhere
from invasion of privacy and breach of security to the server crawling
to a halt or even crashing abruptly. We will discuss some of these
issues in future work.
Acknowledgements
I would like to thank Paul Wrigglesworth, Department of Geography,
Concordia University, Canada, for his assistance in testing Apache
installation on Windows NT.
References
Appendix : Apache Command Line Options
General
These options are applicable to all Apache ports, including UNIX and
Windows 9x/NT.
| OPTION |
FUNCTION |
apache -d serverroot |
Set the initial value for the ServerRoot variable to server root. This can be overridden by the ServerRoot command in the configuration file. The default is /usr/local/apache on UNIX and /apache on Windows. |
apache -D name |
Define a name for use in in IfDefine directives. This
option can be used to optionally enable certain functionality in the configuration file,
or to use a common configuration for several independent hosts, where host specific
information is enclosed in <IfDefine>
sections. |
apache -f
config |
Execute the commands in the file
config on startup. If config does not begin with a /, then it is taken to be
a path relative to the ServerRoot.
The default is httpd.conf. |
apache -C "directive" |
Process the given apache "directive" (just as if it had been part of a configuration file) before actually reading the regular configuration files. |
apache -c "directive" |
Process the given apache "directive" after reading all the regular configuration files. |
apache -X |
Run a single-process mode for internal debugging purposes only. (The daemon does not detach from the terminal or fork any children.) It should not be used to provide ordinary Web service. |
apache -v |
Print the version of httpd and its build date, and then exit. |
apache -V |
Print the base version of httpd, its build date, and a list of compile time settings which influence the behaviour and performance of Apache, then exit. |
apache -L |
Give a list of directives together with expected arguments and places where the directive is valid, then exit. |
apache -l |
Give a list of all modules compiled into the server, then exit. |
apache -h |
Print a list of the httpd options, then exit. |
apache -S |
Show the settings as parsed from the config file (currently only shows a breakdown of the vhost settings) but do not start the server. |
apache -t |
Test the configuration file syntax (i.e., read all configuration files and interpret them) but do not start the server. If the configuration contains errors, display an error message and exit with a non-zero exit status, otherwise display "Syntax OK" and terminate with a zero exit status. |
Table 1. Apache General Command Line Options.
Windows-Specific
| OPTION |
FUNCTION |
| apache |
Start running Apache. |
| apache -f "\path_to\conf\file_name.conf" |
Specify a configuration file. If a configuration file name with -f is not specified, Apache will use the file name compiled into the server, usually httpd.conf. |
| apache -k shutdown (or CTRL-C) |
Signal Apache to stop. You will need to open another console window. |
| apache -k restart |
Signal Apache to restart. This makes it re-read the configuration files. Any transactions in progress are allowed to complete without interruption. |
Table 2. Apache as a Console Application: Command Line Options.
| OPTION |
FUNCTION |
| apache -i -n "service name" |
Install Apache as a service. The default "service name", if one is not specified, is "Apache". |
| apache -u -n "service name" |
Remove an Apache service. |
| apache -i -n "service name" -f "\path_to\conf\file_name.conf" |
Install a service with a specific configuration file. If a configuration file name with -n is not specified, Apache will use the file name compiled into the server, usually httpd.conf. |
| apache -n "service name" -k start |
Start running Apache. |
| apache -n "service name" -k shutdown |
Signal Apache to stop. |
| apache -n "service name" -k restart |
Signal Apache to restart. This makes it re-read the configuration files. Any transactions in progress are allowed to complete without interruption. |
Table 3. Apache as a Service: Command Line Options.
View the profile on Pankaj Kamthan and the list of other Articles by Pankaj Kamthan.
|