Installing Apache on Linux/Unix
This section explains how to install a fresh build of Apache 2.0.x on Linux/Unix. The steps necessary to successfully install Apache from source are
The following sections describe these steps in detail.
Downloading the Apache Source Code
The official Apache download site is located at http://httpd.apache.org/. You can find several Apache versions, packaged with different compression methods. The distribution files are first packed with the 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. (It isn't included in the default installation of many commercial Unix operating systems.)
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. For example, Apache version 2.0.52 is downloaded as a file named httpd-2.0.52.tar.gz. Keep the downloaded file in a directory reserved for source files, such as /usr/src/ or /usr/local/src/.
Uncompressing the Source Code
If you downloaded the tarball compressed with gzip (it will have a tar.gz suffix), you can uncompress it using the gunzip utility (part of the gzip distribution).
By the way
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 this top-level directory to prepare for configuring the software.
Preparing to Build Apache
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:
However, in preparation for the PHP installation in Chapter 4, "Installing and Configuring PHP," you will need to make sure that mod_so is compiled into Apache. This module, named for the Unix shared object (*.so) format, enables the use of dynamic modules such as PHP with Apache. To configure Apache to install itself in a specific location (in this case, /usr/local/apache2/) and to enable the use of mod_so, issue the following command:
#./configure --prefix=/usr/local/apache2 --enable-module=so
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 be read by the make utility, which will carry out those tasks. If everything goes well, after executing configure, you will see a set of messages related to the different checks just performed, and will be returned to the prompt:
... creating test/Makefile config.status: creating docs/conf/httpd-std.conf config.status: creating include/ap_config_layout.h config.status: creating support/apxs config.status: creating support/apachectl config.status: creating support/dbmmanage config.status: creating support/envvars-std config.status: creating support/log_server_status config.status: creating support/logresolve.pl config.status: creating support/phf_abuse_log.cgi config.status: creating support/split-logfile config.status: creating build/rules.mk config.status: creating include/ap_config_auto.h config.status: executing default commands #
If the configure script fails, warnings will appear, alerting you to track down additional software that must be installed, such as compilers or libraries. After you install any missing software, you can try the configure command again, after deleting the config.log and config.status files from the top-level directory.
Building and Installing Apache
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 progress of the compilation, and you will end up back at the prompt. After compilation is finished, you can install Apache by typing make install at the prompt. The makefiles will install files and directories, and return you to the prompt:
... Installing header files Installing man pages and online manual mkdir /usr/local/apache2/man mkdir /usr/local/apache2/man/man1 mkdir /usr/local/apache2/man/man8 mkdir /usr/local/apache2/manual Installing build system files make: Leaving directory '/usr/local/src/httpd-2.0.52' #
The Apache distribution files should now be in the /usr/local/apache2 directory, as specified by the --prefix switch in the configure command. To test that the httpd binary has been correctly built, type the following at the prompt:
# /usr/local/apache2/bin/httpd -v
You should see the following output (your version and build date will be different):
Server version: Apache/2.0.52 Server built: Sep 26 2004 11:47:22
Unless you want to learn how to install Apache on Mac OS X or Windows, skip ahead to the "Apache Configuration File Structure" section to learn about the Apache configuration file.