Getting Started with Apache 2.0, Part 1

In this first article in a three-part series, Harish Kamath helps you download and configure the Apache Web server. If you’ve wanted to use PHP with Apache, look no further; that part of the setup is also covered here.

A PaTCHy Server

The Apache project had its humble beginnings as a set of “patch” files applied to existing Web server software. But it hasn’t looked back since then. With the sincere efforts of “The Apache Group,” this “patchy” piece of software has now become the de-facto leader of all Web servers across the Internet and a torchbearer for all open source projects.

Consider this – as of December 2004, the popular Netcraft Web Server survey – accessible at – claims that there are more than 38 million websites that run on an Apache-powered Web server, giving it a mind-boggling market share of around 67 percent of the entire market. And if that does not convince you, try this – it’s absolutely FREE!

Coming back to this article – the first in a three part series – today, I’ll show you how to install Apache on your own machine. This includes compiling and building the software from scratch, followed by an explanation of the configuration “directives” that help run this Web server and finally, I’ll show you how to configure the latest versions of PHP and Apache to work together – an exciting combination, though I must admit that there are many conflicting views on this topic.

Interested? Flip the page to get started.

{mospagebreak title=Getting Off the Blocks}

There are several ways to install Apache on your server. You could start by downloading a binary distribution built specifically for your operating system, or locate a RPM for your version of Red Hat Linux (or “Fedora,” as it is now known), or you could do what I always do – install it from scratch by compiling the source code.

Before you get started with the compilation, I’ve prepared a little checklist of the requirements in order to ensure a smooth ride:

  • A working installation of your favorite flavor of Linux; mine’s Slackware.

  • Root access to your Linux box to avoid any permissions issues.

  • A functional C compiler, such as gcc.

  • *NIX utilities such tar and gzip/gunzip to work with source code files.

  • A Linux guru, who is only a phone call way to resolve all those pesky “unforeseen” problems.

Next, you’ll need to download the source code of the “best available” version (2.0.52, as of this writing) of the Apache Web server. Note that I’ve selected the Apache 2.0 version over than “widely-installed” 1.3.x version and the “alpha” 2.1 version, for several reasons.

This 2.0 version is equipped with several enhancements, such as platform-specific multi-processing modules (MPMs) and the Apache Portable Runtime (APR), support for latest IPv6 protocol, ease of configuration with a consistent build mechanism and much, much more, as compared to its predecessor, the 1.3.x version. For hardcore techies, this article titled “Apache 2.0: The Internals of the New, Improved” on – – should be an interesting read.

Coming back to the download – select an appropriate mirror website from the download page located at and save the file “httpd-2.0.52.tar.gz” at an appropriate location (say the “/tmp” folder) on your server.

In the next section, I’ll show you how to install the Apache using the default settings that are sufficient to get the Web server to serve static HTML pages.

{mospagebreak title=Compiling Apache}

Now that you’ve downloaded the source code from the Apache website, it’s time to start up your Linux console and fire these commands, one-by-one.

$ cd /usr/local/src/

$ tar -xzvf /tmp/httpd-2.0.52.tar.gz

This should create a directory named “httpd-2.0.52″ with all of the required files. At this stage, I’ll concentrate on the “default” configuration of the Apache Web server, which is sufficient for driving a website consisting of static pages and basic CGI requirements.

I’m pretty sure that most of our readers wish to run PHP scripts on their Apache-driven Web servers. But, there is no reason to panic – later, I’ll also show you how to install PHP version 5.0 and configure the Apache Web server to execute your PHP scripts.

Coming back to the compilation of the Apache source code – navigate to the location where you have unzipped the downloaded archive file and execute the “configure” script, present therein. Here, I have used only one configuration option, i.e. the “–prefix” option. This option allows you to specify the location where you would like to the install the software on the server.

$ cd /usr/local/src/httpd-2.0.52/

$ ./configure –prefix=/usr/local/apache

Behind the scenes, this “configure” script does a quick check in order to ensure that the settings in the configuration files, to be created later, reflect those of your server. Note that you can always review the contents of the “config.log” file (if generated) in order to investigate any errors that you may have encountered.

Once the “configure” script completes execution, the Apache Web server is now ready for installation. The next step: you’ll need to run the “make” command, as shown below.

$ make

While the output of this command does appear daunting (especially for newbies) at first glance, please be assured that all is well – the only time to hit the panic button is when the command stops abruptly with an error message.

The final step: run the “make install” command:

$ make install

Once again, you are subjected to a screen full of cryptic statements. But, if you get to see a final message that looks something like this – make[1]: Leaving directory `/usr/local/src/httpd-2.0.52′ – you can afford to give yourself a little pat on the back because you have successfully installed the Apache Web server. Now, it’s time to test the installation – start up the Web server using the following command:

$ /usr/local/apache/bin/apachectl start

$ lynx http://localhost

and fire up lynx (or any other Web browser) to navigate to the default location, as shown above. If you are able to view the “Test Page for Apache Installation,” you can pop the champagne bottle because your Web server is now ready to serve static HTML websites.

{mospagebreak title=Configuration Options}

In the previous section, I’ve demonstrated how you can get off the blocks by installing an “out-of-box” configuration of the Apache Web server. However, the primary advantage of Open Source software is the ability to customize and fine-tune the software as per your whim and fancy – and the Apache Web server is no different.

In this section, I will outline the options that one can use with the “configure” command – this helps you to compile a Web server that you want rather than force you to use a version that everyone else uses. Talk about power!

Before I list them, I would like to point out that most options, which require you to specify a value, have the following general syntax:


You’ve already been introduced to the “–prefix” option. Now its time to say hello to the “–exec-prefix” option, that allows you to specify the location for the “architecture-dependent” files. All the binary files, C library files,  manual files and so forth are stored under this location. So, you might want to do a re-think before you decide to specify a custom value for this parameter. For the record, this defaults to value specified in the “prefix” option.

Next, you have a bunch of options that allow you to further fine-tune the location of different files, listed in the above paragraph. As the name of each option (in the list below) suggests, each is specific to a particular set of files whose location it controls:

  • the “–bindir” option: you can specify the location for different Apache executables such as httpd, htpasswd, and so forth.

  • the “–includedir” option: the location of the C header files are governed by this parameter.

  • the “–mandir” option allows us to customize where we can install the manual files.

  • the “–sysconfdir” option controls the folder where the configuration files such as the “httpd.conf” are installed.

As already mentioned, one of the distinct advantages of Apache is the ability to fine-tune your local installation because of its modular structure. Each add-on feature, supported by the Web server, is available in the form of a module that can be either compiled statically into the binary or loaded dynamically as a DSO module when the server starts. For example, if you wish to enable LDAP with your Apache installation, you’ll need to enable the “mod_ldap” module.

A little note about DSO (an acronym for Dynamic Shared Objects) modules would be appropriate before I proceed further. It is quite possible that the default configuration of Apache does not support modules that you may need in the future. Consider the “mod_ldap” LDAP module. When you compiled Apache for the first time, you did not foresee the need for this module. However, a few months later, you are asked to enable it. The only option, then, would be to go through the entire rigmarole of compiling the server all over again.

This is not how it works with DSO modules. You can compile the modules that you may (or may not) require in the future as DSO modules (I’ll show you how, in a moment) and then you can tweak the Apache configuration file to load them at start-up, as required.

Coming back to our “configure” command – note that you can disable any modules that are compiled, by default, in the current version of Apache using the following generic syntax:


Here are some of the modules that you can disable with the “configure” command:

  • “–disable-auth” disables the features provided by the “mod_auth” module.

  • “–disable-autoindex” does not allow the server to display directory listings.

  • “–disable-cgi” prevents CGI scripts from being executed on the server.

  • “–disable-include” turns off Server Side Includes in your Web pages.

  • “–disable-http” disables the HTTP protocol itself – DO NOT even think about using this option unless you are really sure of what you’re doing.

That was a just a partial list. The URL at the end of this section will provide you with a complete list of all such modules.

Now that you’ve seen how to disable modules compiled into the Web server, you’ll be surprised to learn that there are some modules which are compiled but not enabled. In order to enable these modules, we have two options: you can use “–enable-mods-shared” that allows us to dynamically load the list of modules, or use the “–enable-modules” option to bind a set of modules statically, as shown below:

$ ./$configure –prefix=/usr/local/apache –enable-mods-
shared=’ldap auth-ldap proxy-http’

The above command will dynamically load the following modules: mod_ldap, mod_auth_ldap and mod_proxy_http where the next command will bind the same modules statically:

$ ./$configure –prefix=/usr/local/apache –enable-modules
=’ldap auth-ldap proxy-http’

And if you are feeling too lazy to list the modules at the command line, you can opt for the “most” and “all” keywords with the “–enable-mods-shared” option, which will compile “most” and “all” modules as DSO modules.

But, there are always a few who love to type;they can use module specific options to enable the corresponding modules. The general syntax for such options is as follows:


This builds the specified module as a DSO where as the following syntax will compile the same module, statically:


You can view a list of all such modules at the following URL:

Finally, there are always some modules that are not a part of the Apache project. For example, if you wish to configure PHP to work with the Apache Web server, you’ll need a generic mechanism that allows you to load third-party Apache modules at start-up. This is where the “–enable-so” option comes in handy – this allows you to load such third-party libraries as the server starts.

That’s about it as far as the powerful “configure” command is concerned. Before you proceed to the next section, take a look at the following URL for more details about the installation process:

{mospagebreak title=The “httpd.conf” Configuration File: a Quick Overview}

In this section, I’ll give you an overview of the “httpd.conf” file located under the “conf” folder of your Apache installation. As you might have guessed, you control the configuration of your Web server by manipulating the entries in this file.

While I’ll refrain from commenting on the more complex features of this configuration file in this part of the tutorial, I will definitely cover the basic “parameters” with which you need to be familiar.

Open this httpd.conf in a text editor and scroll down to view the following parameters or “Directives,” as they are commonly referred to as in Apache-lingo.

  • ServerRoot: this stores the folder under which the “conf” and “log” folders of your Apache installation are present.

  • PidFile: this specifies the name and location of the file where the server stores its process identification number when it starts. By default, the server creates a file called “” in the “logs” folder.

  • Timeout: this value represents the number of seconds the server sends a time out to the client.

  • KeepAlive: it is used to allow (or disallow) persistent connections, i.e. more than one request from clients for a single connection. It is recommended to keep this “On,” the default value.

  • MaxKeepAliveRequests: this directive specifies the number of requests for a persistent connection.

  • KeepAliveTimeout: this parameter specifies the amount of time to wait (in seconds) for the subsequent requests from the client on a persistent connection.

Next, you’ll notice a set of options for the different MPMs supported by your instance of Apache 2.0 version. Here, I’ll recommend that you tweak with the “Directives” associated with the MPM that you have chosen to work with.

The following “Directives” follow:

  • Listen: this allows you to specifically bind the Web server to particular IP addresses and/or ports. This is useful if you would like to run different versions of Apache simultaneously, on the same machine, on different ports.

This is followed by the section where you can list DSO modules that you wish to load when the server starts. For example, if we wish to load the PHP5 module when the server starts, the following “LoadModule” entry is a must:

LoadModule php5_module modules/

The next two sections of the “httpd.conf” file deal with “main” server configuration and the “VirtualHosts” configured on your instance of Apache. For the moment, I shall avoid getting into specifics of these directives in today’s article because of space constraints. But, I promise that I’ll explain these in future tutorials of this Apache series.

{mospagebreak title=PHP 5.0.3 with Apache 2.0.52}

At the onset, I promised that I would demonstrate how to configure PHP 5.0 with Apache 2.0  – and I always keep my promises!

Before I continue any further, I must highlight a warning by “The PHP Group” that the combination of PHP and Apache 2.0 is not recommended in a production environment. You can read the reasons behind this “stern” warning in the official PHP FAQ:

And if you are still not satisfied, read this interesting discussion at the following URL:

If you are still looking to get your hands dirty with this combination, despite all my warnings and caveats – welcome aboard.

This is where you must run a quick check on your existing Apache installation: did you build it to load modules dynamically by specifying the “–enable-so” option? If not, quickly fire the following commands to get moving:

$ cd /usr/local/src/httpd-2.0.52/

$ ./configure –prefix=/usr/local/apache –enable-so

$ make

$ make install

I’ll also assume that you’ve already installed the following:

Next, you’ll need to download the source code for the latest version of PHP (currently 5.0.3) from the following URL:

Unzip the PHP 5 source code on your server and run the “configure” command as shown below.

$ cd /usr/local/sac/

$ tar -xzvf /tmp/php-5.0.3.tar.gz

$ cd php-5.0.3/

$ ./configure –prefix=/usr/local/php5 –with-
apxs2=/usr/local/apache/bin/apes –with-
mysql=/usr/local/mysql –with-glib –with-dir-

Note that I have not enabled many PHP libraries in the above “configure” command. If you plan to use them extensively, it would be wise to review the options that are listed at this URL:, before moving ahead. Note that these options have been listed for PHP 4 compilation; however, they should work for PHP 5 also.

Now, you’ll have to run the “make” and “make install” commands.

$ make

$ make install

Ready to rock-n-roll? Not so fast. There is still one last bit of configuration of the Apache Web server that enables it to identify PHP files and pass them to the PHP module for interpretation. This is only possible by editing the ubiquitous “httpd.conf” Apache configuration file in your favorite text editor and adding the following line:

AddType application/x-httpd-php .php

Now, you can re-start Apache using the “apachectl” script and load the following “phpinfo.php” script (saved in the root folder of the Web server) in a browser:




Instead of getting a screen full of cryptic error messages or warnings, if you get the following screen, rest assured that you have successfully installed PHP 5.0 with Apache 2.0.

Finally, you can visit the following URL if you wish to learn more about installing PHP with Apache 2.0:

{mospagebreak title=Conclusion}

That’s about it for this article. If you’re interested in learning more, take a look at the following links:

The official Apache Web server website:

The official Apache Documentation on-line:

Compiling and Installing Apache:

Listing of binary distributions:

Apache 2.0: The Internals of the New, Improved –

An Amble Through Apache Configuration –

In the next part of this series, I shall show you how to customize the format of the log files generated by the Apache Web server, how to set up “Virtual Hosts” that give you the ability to run multiple Web sites on single machine and much more. Stay tuned.

Note: All examples in this article have been tested on Linux/i586 with Apache 2.0.52, MySQL 3.23 and PHP 5.0.3. Examples are illustrative only, and are definitely NOT meant for a production environment.

Google+ Comments

Google+ Comments