Compile a Program From Source

How to Compile a Program From Source

No matter what skills you have as a Linux users, beginner or expert, a time will come when you need to have the skills to compile a program from source.  Dealing with source code is just one of those skills that you will need to develop.  This tutorial is a simple way to compile Apache, the common web server.  This is just a start on what you will need to do.  Be sure to practice these skills on a box that is not a production server.

In preparation for compilation you will want to remove apache if you have it installed. This may not be a simple:

Use this command if you have Red Hat based distros.

rpm -e httpd

or use this command with Debian based distros.

apt-get remove apache2

as you will probably have modules that are configured with your installation so you will also need to remove them one at a time. Possible modules might be:



Once you remove httpd, you will see the configuration file saved as httpd.conf.rpmsave.

Step #1: Download the Source Code
The source code is available at the link below and will be in a *.tar.gz format.

mv httpd-2.2.8.tar.gz /usr/src

Move into the directory /usr/src/ that has the source code.

cd /usr/src

Now untar and uncompress the file.

tar zxvf httpd-2.2.8.tar.gz /usr/src

This will create a new directory called httpd-2.2.8. Move into the directory.

cd httpd-2.2.8

List the contents


ABOUT_APACHE CHANGES include modules srclib

acinclude.m4 config.layout INSTALL NOTICE support

Apache.dsw configure InstallBin.dsp NWGNUmakefile test LAYOUT os VERSIONING

build docs libhttpd.dsp README

BuildAll.dsp emacs-style LICENSE README.platforms

BuildBin.dsp httpd.dsp ROADMAP

buildconf httpd.spec server

Step #2: Configure Apache

The next step is to begin the compilation for apache. You will start this process by looking for a configure script. This configure script will prepare the software for compilation. It will check for the version of compiler on the system and if all the required libraries are available. This also will enable you to make decisions about changes you want to make when the software is installed.

If you run help with the configure script you will see a lot of options that are available. Note the ./ in front of the configure script.

./configure --help

This is a good reference for finding ways to improve your installation of apache. For a test install you may want to create a separate folder you could easily remove if you wanted to install another version of apache.

mkdir /usr/local/apache3

./configure - -prefix=/usr/local/apache3 - -enable-so

This will install the apache into an apache3 directory that you could wipe out later, it determines the location of the install. The default would be /usr/local/apache2. The - -enable-so will enable the module so. This will provide the ability to load shared modules like PHP and Apache.

If you want to configure apache to enable options or to compile with options you need to separate options by a space, see the example.

./configure –prefix=/usr/local/apache3 - -enable-ssl - -enable-proxy-http - -enable-so

Once you run the ./configure you will need to run the command: make/


The make command reads a Makefile in the source directory. The Makefile provides the steps for configuring apache with specific instructions. This will start the process of compiling, which may take some time. Once it is done the source has been compiled. Now the next command to run is:

make install

This command actually install apache in the directory that you choose. Once it is complete you can start apache, following the example of /usr/local/apache3, by using this command:

/usr/local/apache3/bin/apachectl start