Previous hours introduced you to the architecture of the Web and Apache. At this point, you are ready to install Apache and get to work. In this hour, you will learn
How to download, compile, and install a basic Apache server on Unix
How to download and install a basic Apache server on Windows operating systems
This hour also covers binary, source, and prepackaged installations.
Several options are available to get a basic Apache installation in place. Apache is open source, meaning that you can have access to the full source code of the software, which in turn enables you to build your own custom sever. Additionally, pre-built Apache binary distributions are available for most modern Unix platforms. Finally, Apache comes already bundled with a variety of Linux distributions, and commercial versions can be purchased from software vendors such as Covalent Technologies and IBM.
Building from source gives you the greatest flexibility, enabling you to build a custom server, remove modules you do not need, and extend the server with third-party modules. Building Apache from source code enables you to easily upgrade to the latest versions and quickly apply security patches. Updated versions from vendors usually take days or weeks to appear.
Building Apache from the source code is not that difficult for simple installations, but can grow in complexity when third-party modules and libraries are involved. Hour 18, "Extending Apache," explains how to extend Apache.
Unix binary installations are available from vendors and can also be downloaded from the Apache Software Foundation Web site. They provide a convenient way to install Apache for first-time users.
Third-party commercial vendors provide prepackaged Apache installations together with an application server, additional modules, support, and so on.
The ASF provides an installer for Windows systemsa platform where a compiler is not as commonly available as in Unix systems.
Starting with Apache 2.0, Apache server releases are named with three digits and an optional qualifier (alpha or beta). The first digit refers to the main Apache release version, the second digit to the major revision, and the third digit to the minor revision. A qualifier of alpha means that the code has not reached production-level quality and the feature set is subject to change. In general, only developers working on the Apache code base or advanced users curious about the latest features should run alpha code. A beta version means that although the code is still not production-ready, the feature set is more or less complete and the server is considered stable enough for general testing. A sample Apache release name is 2.0.28-beta.
Note
As a side note, Apache developers take great pride in the quality of their code. As a result, beta versions of Apache are much more stable and feature-rich than commercial product beta software. The drawback is that sometimes the development cycle takes way too long.
This section explains how to install Apache on Unix and Unix-like systems such as Solaris, Linux, and FreeBSD.
If you are running a modern Linux distribution, chances are that Apache is already installed in your system. Try the following at the command-line prompt:
# httpd -v
Because some distributions name the Apache binary httpd2, you can also try the following:
# httpd2 -v
If Apache is installed and the binary is in your path, you will get a message with the version and build time:
Server version: Apache/2.0.28 Server built: Dec 29 2001 10:32:01
Otherwise, you will get command not found or a similar message. It might be that Apache is already installed but is in a different path or with a different binary name, such as httpd2. Check whether /usr/local/apache2/ or /etc/httpd2 exists and contains a valid Apache 2.0 installation.
This books covers Apache 2.0, so you must make sure that this is the version installed in your server. An existing 1.3 Apache installation is likely to interfere with your new Apache if the older installation runs at startup. Make sure that either the package is removed from the operating system or the startup script, if any, is disabled. For example, in most Linux distributions, this means modifying the startup scripts at /etc/rc.d/. Apache 1.3 and 2.0 can coexist and run simultaneously if they use different IP address and port combinations, as explained in Hour 4.
If Apache 2.0 is already installed in your system, you can skip the following sections and go directly to Hour 4, "Getting Started with Apache." You can always read this hour later if you decide to build your own server.
The steps necessary to successfully install Apache from source are
Downloading the software
Running the configuration script
Compiling the code and installing it
These steps are described now in detail.
The official Apache download site is located at http://www.apache.org/dist/httpd. You can find several Apache versions, packaged with different compression methods. The distribution files are first packed with the Unix tar utility and then compressed either with the gzip tool or the compress utility. Download the .tar.gz version if you have the gunzip utility installed in your system. This utility comes installed by default in open source operating systems such as FreeBSD and Linux. Download the tar.Z file if gunzip is not present in your system, such as in the default installation of many commercial Unix operating systems.
Note
The gzip, gunzip, and gtar programs are useful tools. The Gzip Web site at http://www.gzip.org provides you with links to the source code and binaries for Unix platforms such as Solaris, AIX, and HP-UX. If gunzip is not installed but gzip is available in your system, you can use gzip -d instead.
The file you want to download will be named something similar to httpd-2_0_version.tar.Z or httpd-2_0_version.tar.gz where version is the most recent release version of Apache.
If you downloaded the tarball compressed with gzip (tar.gz suffix), you can uncompress it using the gunzip utility (part of the gzip distribution).
Note
Tarball is a commonly used nickname for software packed using the tar utility.
You can uncompress and unpack the software by typing the following command:
# gunzip < httpd-2_0*.tar.gz | tar xvf -
If you downloaded the tarball compressed with compress (tar.Z suffix), you can issue the following command:
# cat httpd-2_0*.tar.Z | uncompress | tar xvf -
Uncompressing the tarball creates a structure of directories, with the top-level directory named httpd-2.0_version. Change your current directory to the top-level directory.
You can specify which features the resulting binary will have by using the configure script, in the top-level distribution directory. By default, Apache will be compiled with a set of standard modules compiled statically and will be installed in the /usr/local/apache2 directory. If you are happy with these settings, you can issue the following command to configure Apache:
#./configure
For the remainder of the book, it is assumed that you compiled Apache with loadable module support and built most of the modules as such. This, combined with the Apache extension utility (apxs), will enable you to extend the server later with third-party modules without the need to recompile, as described in Hour 18.
To configure Apache this way, issue the following command:
#./configure --enable-so --enable-mods-shared=most
If you are installing Apache as a normal user and you don't have write permissions on /usr/local/, or you simply want to install Apache on a different location, you can specify an alternative location using the --prefix option. For example, the following line:
#./configure --enable-so --enable-mods-shared=most--prefix=/home/username/apache2
will compile Apache to be installed in the home directory of the username user.
The purpose of the configure script is to figure out everything related to finding libraries, compile time options, platform-specific differences, and so on, and to create a set of special files called makefiles. Makefiles contain instructions to perform different tasks, called targets, such as building Apache. These files will then be read by the Unix make utility, which will carry on those tasks. If everything goes well, after executing configure, you will see a set of messages related to the different checks just performed and you will be ready to compile the software.
The make utility reads the information stored in the makefiles and builds the server and modules. Type make at the command line to build Apache. You will see several messages indicating the compilation progress. After compilation is finished, you can install Apache by typing make install. The Apache distribution files will be copied to /usr/local/apache2 or the target directory specified with the --prefix switch.
The Apache configuration script, configure, can take additional options. Many of them are irrelevant for most users, either because they are rarely used or they relate to building Apache distribution packages. A number of them deal with enabling or disabling specific modules, and those are explained in detail in Hour 18. Table 3.1 describes the most useful configuration options. You can get a complete listing by issuing the ./configure --help command.
|
--with-mpm=mpm |
Specifies the Apache Multi-Processing Module. If this option is not specified, the default MPM for the platform will be compiled in. In Unix, the value for mpm can be either worker, perchild, or prefork. MPMs are discussed in Hour 11, "Multi-Processing Modules." |
|
--enable-so |
Enables loadable module support. |
|
--prefix=path |
Apache will be installed relative to the value of the path directory. By default, Apache will be installed in /usr/local/apache2. |
|
--enable-module |
Enables or disables the specified module. Check Hour 18 for a complete module listing and descriptions. |
|
--enable-modules=list |
Another way of specifying which modules to build, either compiled into the server or as shared libraries. Both switches can take either a list of modules, all (all modules bundled with Apache), or most (includes the majority of the modules you will need). |
Hour 11 explains the role of Multi-Processing Modules. Table 3.2 shows the relationship between platforms and MPMs.
|
Platform |
Available MPMs |
|
Windows NT/2000/XP |
winnt |
|
BeOS |
Beos |
|
OS/2 |
mpmt_os2 |
|
Linux |
worker, prefork (default), perchild |
|
Solaris |
worker, prefork (default), perchild |
|
HP-UX |
worker, prefork (default), perchild |
|
AIX |
worker (recommended), prefork (default), perchild |
|
Mac OS X |
worker, prefork (default), perchild |
|
FreeBSD |
worker, prefork (default), perchild |
|
Cygwin |
prefork (default) |
In the Windows, BeOS, and OS/2 platforms, there is no choice of MPM and the appropriate one will be selected. In Unix platforms, the default is the prefork MPM, although the worker MPM is probably a better choice, except for some platforms such as FreeBSD. The Cygwin platform supported only the prefork MPM at the time this book was being written. Table 3.2 gives you information about which MPM modules are available for a specific platform. Further information on which MPM to choose, their advantages and disadvantages can be found in Hour 11.
This section explains how to install a pre-built Apache server on Unix platforms.
You can download binaries for different platforms from the Apache Web site at http://www.apache.org/dist/httpd/binaries. Check whether binaries for your platform are available. You can download and uncompress the tarball as described in the previous section. In this case, the configuration and compilation steps are not necessary. You can install the software by executing the install-bindist script. You can pass an optional argument, the target installation directory. Otherwise, the software will be installed in /usr/local/apache2.
Operating system vendors recognize that Apache is an important server software component and either include it by default or make it available in a distribution-specific format.
For Linux distributions based on the RPM format, you can query whether Apache 2.0 is already installed by issuing this command:
#rpm -q apache2
If Apache 2.0 is not available, you can go to the distribution vendor Web site, download the Apache 2.0 RPM, and install it executing the following command as root:
#rpm -i apache2*.rpm
Apache 2.0 is part of the FreeBSD and other BSD flavors ports collection. Just change to the appropriate directory and type make install. That command will download the source code, and build and install the server.
You can get Apache binaries and packages for Solaris platforms at http://www.sunfreeware.com. Solaris 8 already bundles an Apache 1.3 version, and future releases will likely include Apache 2.0.
CVS stands for concurrent versioning system and is a popular software development tool that enables programmers to simultaneously work on the same code base, keeping track of changes and revisions and helping to resolve conflicts in the code. Apache is an open source project and makes the source code available via a public CVS server. You can check out any particular release of the code or the latest, unreleased version this way. Compiling and building from CVS is an advanced topic and not recommended for beginners. The following sections comprise a step-by-step guide to compiling Apache from CVS.
You need the cvs command-line utility to connect to the Apache CVS repository. It is available by default in most Linux distributions and other open source operating systems such as FreeBSD. If cvs is not available for your system, check your vendor package repository or download and compile the source from http://www.cvshome.org.
The main Apache CVS repository is at cvs.apache.org. The first step will be to log in to that server:
# cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic login
You will be prompted for a password; use anoncvs.
To retrieve the Apache source code (check out the code in the jargon), issue the following command:
# cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic co httpd-2.0
The httpd-2.0 directory that contains the Apache source code will be created. The packaged source tarball for Apache includes a couple of libraries that are not present in CVS apr and apr-util. Change your directory to httpd-2.0/srclib/ and execute the following commands:
# cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic co apr # cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic co apr-util
You need to change your current directory to httpd-2.0 and execute the ./buildconf command. That will create a configure script. From this step on, you can follow the instructions in the "Building Apache from Source" section earlier in the hour. The buildconf script requires the autoconf utility, which is either already included with your system or can be downloaded from http://www.gnu.org/software/autoconf.
You can check out a specific version of Apache by using the -r tag option to the cvs command-line utility. For example, this line
# cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublicco -r APACHE_2_0_28 httpd-2.0
will check out the source code for Apache 2.0.28.
Apache 2.0 runs on most Windows platforms and offers increased performance and stability over previous 1.3 Windows versions. You can build Apache from source, but because not many Windows users have compilers, this section deals with the binary installer.
Before installing Apache, you probably want to make sure that you are not currently running a Web server in that machine, such as a previous version of Apache, Microsoft Internet Information Server, or Microsoft Personal Web Server. You might want to uninstall or otherwise disable existing servers. You can run several Web servers but they will need to run in different address and port combinations.
You can download an installer in the MSI format from http://www.apache.org/dist/httpd/binaries/win32.
After you download the installer, double-click on the file to start the installation process. You will get a welcome screen, as shown in Figure 3.1, and you will be prompted to accept the Apache license. You can also find a copy of the license in the Apache Software Foundation Web site (http://www.apache.org) and in Appendix A, "Apache License," of this book. Basically the license says that you can do whatever you want with the softwareincluding proprietary modifications except claim that you wrote it.
Figure 3.1
Windows installer welcome screen.
After you accept the license, you are presented with a brief introduction to Apache. Following that, you are asked to provide the installation process with basic information about your computer, as shown in Figure 3.2. This includes the network domain name, the fully qualified domain name (FQDN) for the server, and the administrator's e-mail address. The server name will be the name that your clients will use to access your server, and the administrator e-mail address will be added to error messages so that visitors know how to contact you when something goes wrong. Additionally, you can install Apache as a service or require it to be started manually. Installing Apache as a service will cause it to run every time Windows is started, and you can control it through the usual Windows service administration tools. Choose this option if you plan to run Apache in a production environment or otherwise require Apache to run continuously. Installing Apache for the current user will require you to start Apache manually and set the default port Apache listens to requests to 8080. Choose this option if you use Apache for testing or if you already have a Web server running on port 80. Hour 4 provides further information on the different ways of controlling Apache in Windows.
The following screen enables you to choose the type of installation, as shown in Figure 3.3. Typical installation means that Apache binaries and documentation will be installed, but headers and libraries will not. This is the best option to choose unless you plan to compile your own modules.
A custom installation enables you to choose whether to install header files or documentation. After selecting the target installation directory, which defaults to c:\Program Files\Apache Group, the program will proceed with the installation process. If everything goes well, you will be presented with the final screen shown in Figure 3.4.
Figure 3.2
Basic information screen.
Figure 3.3
Installation type selection screen.
Figure 3.4
Successful installation screen.
At the time this book was written, Apache 2.0 did not support Windows consumer platforms such as Windows 95 and Windows 98. The Apache developers will concentrate on the server platforms such as Windows 2000 and Windows XP, and when Apache has been optimized for these platforms, they might attempt to support consumer versions of Windows.
Additionally, the current releases of the installer at the time of writing did not contain support for encryption, although future releases will likely include the OpenSSL libraries by default. Hour 17, "Setting Up a Secure Server," explains the SSL protocol.
When downloading binaries from the Internet, you must make sure that the software is indeed what you expect it to be. If the Web site has been compromised, the software could have been replaced by one containing viruses or backdoors. Apache Software Foundation members digitally sign the released software, so you can check that an attacker has not modified it. The signatures are contained in the files with asc extensions. You can find instructions on how to check the validity of the signatures at http://httpd.apache.org/docs-2.0/install.html#download.
If you are installing Apache from an RPM provided by your vendor, there is a similar mechanism to check its integrity and authenticity with the -K option, as shown here:
# rpm -v -K package.rpm
In addition to the operating-system-vendor-supplied Apache versions, a number of companies offer servers based on Apache.
IBM: The latest IBM HTTP server is based on Apache 2.0 with additional modules added (such as encryption). The IBM HTTP server is also part of the Websphere Application Server suite. You can find more about this server at http://www-4.ibm.com/software/webservers/httpservers.
Covalent: Covalent offers Enterprise Ready Server (ERS), based on Apache 2.0. ERS includes support for SSL, FTP, and LDAP, and includes a graphical management interface component. You can find more about ERS at http://www.covalent.net.
Red Hat: Although at the time this book was written, Red Hat did not offer a 2.0-based Web server, it is likely to do so in the future as part of its secure and commerce servers. More information about Red Hat's Apache products can be found at http://www.redhat.com/software/apache/index.html.
This hour explained different ways of getting an Apache 2.0 server installed on your Unix or Windows machine. It covered both binary and source installation and explained the basic build time options. Hour 16, "Tuning Apache," covers additional build configuration options and tools. The lesson in Hour 4 will guide you through the different steps necessary to get the Apache server you just installed up and running so that you can start serving pages.
Are there any tools available to help with Apache compilation?
Several programs, usually referred to as compilation kits, are designed to make it easier to compile Apache and additional modules. They present a text interface from which you can specify the desired options and modules to enable. The compilation tool takes care of downloading and patching the necessary software, and configuring and building it. You can find one of these tools at http://www.apachetoolbox.com, although it only supports 1.3 at the time of writing this book.
Why do some Apache releases seem to be missing?
When Apache developers agree it is time to make a new release of the server, they mark the sources with the release name and number and proceed to create the source and binary distribution packages, test them, place them in the Web site, and announce it to the world. If a severe problem is found in that testing, the release process is stopped until the problems are fixed. To avoid confusion, a new release name and number will be applied to the next release attempt that includes the new fixes. That is the reason why, for example, there were no public releases between Apache 2.0.16 and 2.0.28. You can always access any version using the CVS repository, as explained earlier in this hour.
How can I start a clean build?
If you need to build a new Apache from source and do not want the result of earlier builds to affect the new one, it is always a good idea to run the make clean command. That will take care of cleaning up any existing binaries, intermediate object files, and so on.
Why is it important to make sure that an existing Apache server is not enabled?
How can you specify the location to install Apache?
Only one server can be listening at the same IP and port combination at any given moment. Having previous versions of Apache running will prevent new ones from running and will likely confuse you.
You can use the --prefix option of the configure script. If an existing installation is present at that location, the configuration files will be preserved but the binaries will be replaced.
By far the easiest way to get started with Apache is to use the Apache server included with your operating system (if possible). As you become more experienced with Apache and you need to customize or extend it in particular ways, it is useful to build your own version from source. Hour 18 deals with extending Apache and describes several utilities that can help you do so.
The OpenPKG project provides a consistent way to install server software, including Apache, across a variety of platforms. It is a nice alternative to building Apache from source or using the Apache versions provided by your vendor. The OpenPKG project is open source, supports different operating systems such as Solaris, Linux, and FreeBSD, and it was started by Ralf S. Engelschall, author of several popular Apache modules. You can learn more about OpenPKG at http://www.openpkg.org.
The document at this URL describes how to get started compiling and installing Apache on Unix:
http://httpd.apache.org/docs-2.0/install.html
In the following URLs, you will find the equivalent information for Windows-based platforms, including compilation from source:
http://httpd.apache.org/docs-2.0/platform/windows.html
http://httpd.apache.org/docs-2.0/platform/win_compiling.html
For advanced Apache users, or if you want to become involved in development, the Apache developers' site includes information on CVS access, applying patches, and so on: