More and more, organizations of all sizes are hosting or colocating their own Web sites as they integrate their Web presence with back-end systems. A large number of these organizations choose Apache Web server as the platform on which to run their Web site because of its reputation for reliability and cost-efficiency. It also doesn’t hurt that Apache currently has more than 60 percent market share among Web server platforms and boasts the hosting of over 7 million Web sites worldwide. Plus, many choose to run Apache on Linux, which can offer additional benefits. In this article, we’re going to look at your options for acquiring and installing Apache on Linux. In a follow-up article, we’ll cover basic Apache configuration.
Apache, like Linux, is an open source development effort, so there is no cost for the software. Most Linux distributions include a version of Apache. However, for security and stability, it’s always good to start with the latest version of Apache. You can download the latest source code and binaries (1.3.20 at the writing of this article) from http://httpd.apache.org/dist/httpd/ or from one of the many mirror sites linked from the apache.org Web site.
The Apache download site provides versions of Apache for various processors and in a few different archive formats. For the purpose of this article, we will focus on the popular tar.gz archive format. Once you download the appropriate file, you are ready to install Apache from source.
However, if you are running a Linux distribution that uses RPMs (such as Red Hat, Mandrake, and SuSE) or a Debian-compatible distribution with its package manager, you’ll more than likely want to download an Apache package in one of those formats. To find an appropriate RPM, I recommend http://www.rpmfind.net. It has an excellent database of software packages and a powerful search feature. For Debian users, “apt-get install apache” will usually do the trick for finding a good Apache package. Alternatively, you can download the .DEB files from http://www.debian.org/distrib/packages.
First, we’re going to look at installing Apache from the source code, and then we will explain how to install it using the package managers.
Installing from source
Once you have downloaded the file, the next step will be to log in as root or use the su command. Most packages require root permissions to install the Apache files onto your system and make the necessary changes to the Linux environment. Once you have done that, you’ll need to extract Apache from the archive. Go to the directory where you downloaded the Apache tar.gz file and issue the following command:
tar xvfz apache_1.3.20.tar.gz [use the name of the file you downloaded]
This will extract the files verbosely (showing you commentary along the way) while maintaining the file system structure. It will also run gzip on the file before sending it to tar. There should now be a directory named apache_1.3.20. Move into this directory, where you will configure Apache, make the source, and install the binaries. The quickest and simplest way to get started is to issue the following commands:
This will install Apache into the default directory, /usr/local/apache, with all the standard options. The installation directory can be changed with the —prefix flag in the form of —prefix=/var/apache/. Apache can now be started with the command apachectl start. If you execute apachectl by itself, it will give you a list of other options available, which include stop, restart, status, and configtest. Note that during this and all types of installations, you should verify that the server started by viewing the current process list. The command ps aux will display every process currently running, which should include apache or httpd. If you do not see one of the two, check the Apache error.log as it may provide some insight as to what is causing the failure.
Installing from RPM
RPM was created by Red Hat and is an excellent packaging system. A package in this format includes either a precompiled binary or source code and will install everything based on the system defaults. It will also maintain a database of packages currently installed and will notify you of dependencies and conflicts. While this does not allow for as much specificity as compiling from original source, it does make the task incredibly simple. Additional support for other software can always be loaded later without the need to compile any source, as we will see in a minute. To install from an RPM, execute the following command:
rpm –ivh apache-1.3.20.i386.rpm[use the name of the file you downloaded]
This will install the package verbosely and show a hash mark process indicator. It should also start the server automatically, but check the list of processes to be sure. For more information and options, visit http://rpm.redhat.com. There you will find the latest version of RPM, as well as detailed documentation on how to use it.
Installing under Debian
Debian is another Linux distribution, and it contains its own packaging system. Known as Apt, the system provides for on-the-fly installation of thousands of packages. Just like RPM, it will maintain a database of installed packages and will even download dependencies automatically. Make sure you have an updated list by executing apt-get update prior to your apt-get install apache. Another option is to install packages the old-fashioned way (the original Debian method) with dpkg, as in the following example:
dpkg –i apache_1.3.9-13.2.deb [use the name of the file you downloaded]
The installation phase is a good time to configure some Apache modules that are helpful in building a robust and secure Web site. Of course, you can install additional modules at any time, since Apache includes support for dynamically loaded modules. Some popular options that we will look at are Perl, PHP, and SSL.
Perl integration with Apache is provided by the mod_perl package. This package allows for the creation of Apache modules in Perl, as well as providing the benefits of an embedded interpreter. This translates into an alternative to CGI, offering increased power and speed.
You should already have installed a version of Perl as part of your Linux distribution. If you don’t have Perl, the latest version is available at http://www.perl.com/CPAN/src/latest.tar.gz. You should install it before installing mod_perl for Apache.
Download mod_perl at http://perl.apache.org/dist/ and proceed to untar the package as we did above with the Apache package using tar xvfz and the name of the mod_perl package. Having done this, be sure to read over the multiple INSTALL documentation files provided to see which one is right for you. You can choose to have mod_perl install the Apache source at the time of its installation or install and configure it separately. This is one of the reasons to know in advance what features you would like to include on your server. It can be easier to do all at once. To install, execute the following from the mod_perl directory:
The Makefile.PL will prompt you for installation options, including the location of the Apache source and whether you want to compile the Apache Web server at that time. A book could be written on implementing Perl into Apache alone, so be sure to check out http://perl.apache.org/ before getting started.
The latest version of PHP—a popular server-side, HTML-embedded scripting language—can be downloaded from http://www.php.net. Once again, you have the option of configuring PHP during the installation of Apache or adding it later. Regardless of which route you take, you need to configure and install PHP before performing either method. Go ahead and run ./configure in the PHP directory with the —with-apache=/path/to/apache option, then make, and finally make install. It would also be a good idea to include —with-mysql as well if there is chance you will add MySQL database support later. To install during the initial configuration of Apache, run ./configure from the Apache directory with the following arguments:
./configure —activate-module=src/modules/php3/libphp3.a (for PHP version 3)
./configure —activate-module=src/modules/php4/libphp4.a (for PHP version 4)
To install onto a system with a preconfigured version of Apache, be sure to stop the server first with the apachectl stop command. Next, configure PHP as follows:
./configure —with-apxs —with-mysql
The apxs utility allows for the creation and installation of extension modules for the Apache HTTP server. This involves building a DSO (Dynamic Shared Object) and having it loaded into Apache at runtime. To use this, be sure to build Apache with the mod_so module enabled. This should be done by default, but you can verify by running apache –l, which will print out a list of compiled-in modules. Now we need to add a LoadModule command in httpd.conf and an AddType command in srm.conf:
LoadModule php4_module /usr/lib/apache/1.3/libphp4.so
AddType application/x-httpd-php .php3
Secure Socket Layer (SSL) enables your Web site to send confidential information over the wire in an encrypted state. It is now a standard component for nearly every Web site. Apache SSL support comes in a couple of main options.
You can download Apache-SSL, which is the complete Web server source with SSL built in. By compiling and installing this in similar ways to the original source, you can be running an SSL compatible server in the same amount of time it would take to install the standard Apache server. Another option is provided by mod_ssl, which provides SSL support in the form of an Apache module. You can add this before or after compilation, just like PHP and mod_perl. So if you already have Apache up and running and don’t feel like recompiling to add SSL support, this is the way to go. To accomplish this, simply download the mod_ssl module and load it. However, be sure to have OpenSSL installed prior to adding the DSO to Apache.
When all is said and done, Apache provides an extremely cost-effective and robust Web server that has great extensibility since you can add various modules. With the addition of compiled-in or dynamic module support for such packages as Perl, PHP, and SSL, you can build a fast, robust, and secure Web site. In my next article, we’ll look at the basic options you need to configure to get Apache up and running on your Linux system.
What tips do you have for working with Apache?
We look forward to getting your input and hearing about your experiences regarding this topic. Join the discussion below or send the editor an e-mail.