In this tutorial we take a look at compiling Apache HTTPD server from source. One of the main reasons for using the source code is that you can create a version of Apache tailored for your needs. There are many options that can be configured when Apache is compiled and tailored to your needs. Take a look at the following screenshot detailing the output from the configure script when run with –help. So lets go A’la carte rather than Table d’hote.
The version of Apache changes fairly regularly, as new features are added or existing ones enhanced. It is worth checking from time to time for the current release of Apache. A typical download will be in ‘zipped tar format’ for UNIX systems or ‘zipped’ format for windows systems At the time of writing the most recent version available is 2.4.6 and that is dated February 2013.
This can be downloaded from the following local your local Apache mirror
We will look at a typical download and build for a Centos 6.4 system. In the example this is a new clean install of a minimal server.To start we install the prerequisite software, remember that we have a minimal server so we have very little extra.
yum install wget make gcc openssl-devel pcre-devel w3m
We will use wget to download the source code and later we can use w3m, a command line browser to view the web site. The compiler is gcc and we need make to read the instructions for the compiler. We will need the openssl package to build in ssl support to Apache as with the pcre package for regular expressions. Now we can download the source code. We will need the httpd source and the apr, Apache Runtime sources
cd /usr/src wget http://yourlocalmirror/sites/rsync.apache.org/httpd/httpd-2.4.6.tar.gz wget http://yourlocalmirror/sites/rsync.apache.org/apr/apr-util-1.5.2.tar.gz wget http://yourlocalmirror/sites/rsync.apache.org/apr/apr-1.4.8.tar.gz
With the three archives downloaded we can expand then one by one whilst we are in the directory /usr/src
tar -xzvf httpd-2.4.6.tar.gz tar -xzvf apr-util-1.5.2.tar.gz tar -xzvf apr-1.4.8.tar.gz
The apr tools need to be included into the httpd compilation so we move the folders into the httpd directory:
mv /usr/src/ apr-util-1.5.2 /usr/src/http-2.4.6/srclib/apr-util mv /usr/src/ apr-1.4.8 /usr/src/http-2.4.6/srclib/apr
After extracting the contents of the tar.gz files we have a structure that will look similar to the following when looking at the /usr/src/httpd-2.4.6 directory. We can see the executable file configure which we use to create the “makefile” instructions for the compiler, as we saw earlier using the –help option with configure shows all of the settings available.
In order to build Apache you need to have either the ANSI C complier installed or more commonly a copy of the GNU gcc compiler installed. This we did when we installed gcc earlier. A lot of the preliminary tasks for compiling Apache are now carried out using the pre-built configure script supplied as part of the distribution. To build a default installation, good for testing but not recommended to a production server, you simply run ./configure. This will examine the distribution and the OS and build a set of Makefiles for the complier. These Makefiles form the basis of the Apache build.
If we choose to run configure with options we could choose something like this:
./configure --enable-ssl --enable-so --with-included-apr
- –enable-ssl : enables ssl support directly in Apache without the need of additional modules, mod_ssl is compiled into the httpd
- –enable-so : enables support for dynamic modules using DSO; this means that additional modules can be loaded using the LoadModule directive without the need for recompiling
- –with-included-apr : enables the Apache runtime program and utility to be added from the source code we added into the srclib directory earlier. If you are running the very latest version of Apache this is often required as the OS supplied versions of APR are often not at the required level
The next step is to do the initial build by running the make utility; this reads the Makefile and carries out the build. If this phase completes successfully, the final step is to run the make utility again with the install keyword, make install. This completes the build and installs Apache into a set of pre-defined directories.
We can test the install of Apache now on our CentOS 6.4 system. We do not have any start-up scripts in the /etc/init.d directory but we could of course create them. To start the server
We can view the default page using the command line browser
This opens the index.html found in the DocumentRoot which is /usr/local/apache2/htdocs. We can see the results of our labour in the following screenshot that shows the index page as seen through the w3m browser: