Support free tutorials

vogella training Training Books

Apache HTTP Server - Tutorial

Lars Vogel

Version 1.1


Apache HTTP

This articles contains some information about handling the Apache HTTP server.

Table of Contents

1. Apache HTTP
2. Installation
3. Apache HTTP
3.1. Commands
3.2. Configuration Files
3.3. Multi-Processing-Module (MPMs)
3.4. Checking for Apache HTTP problems
3.5. Apache Configuration via .htaccess
3.6. Performance - Turn on gzip compression
4. Configuring virtual hosts in Apache
4.1. What are virtual hosts in Apache?
4.2. How to configure vhosts under Ubuntu
5. About this website
5.1. Donate to support free tutorials
5.2. Questions and discussion
5.3. License for this tutorial and its code
6. Links and Literature

1. Apache HTTP

The Apache HTTP server Ppoject is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows NT.

The Apache HTTP web server is still the most used web server worldwide.

2. Installation

On Ubuntu you can install the Apache HTTP server with the following command.

sudo apt-get install apache2 

The Apache HTTP server provides a selection of Multi-Processing Modules (MPMs) which are responsible for binding to network ports on the machine, accepting requests, and dispatching children to handle the requests. On Ubuntu you can select one of them via one of the following commands.

# install the event MPM
# this is supposted to be less resource intensive
sudo apt-get install apache2-mpm-event

# install the worker MPM
sudo apt-get install apache2-mpm-worker

# install the worker MPM
sudo apt-get install apache2-mpm-prefork 

3. Apache HTTP

The following describes the configuration files and commands for the Apache HTTP web server on Ubuntu.

3.1. Commands

Table 1. 

Command Description
/etc/init.d/apache2 -l List the available modules of Apache
/etc/init.d/apache2 restart Restart the apache2 web server

3.2. Configuration Files

The main configuration file for the Apache Http server is the /etc/apache2/apache2.conf file.

The error log of Apache is located in the /var/log/apache2/error.log file.

3.3. Multi-Processing-Module (MPMs)

Apache HTTP can be running in different modes. These modes determine how the web requests of users are answered. These modes are called Multi-Processing-Module (MPMs). The selected mode is compiled into the server and can be seen via the following command.

apache2 -l 

You find several sections in apache2.conf for configuring the different modules. Configure only the module which your server is using. For example if you see the modul "prefork.c" then you only need to configure the "mpm_prefork_module".

The following listing shows a configuration for a high traffic web server using the prefork module

<IfModule mpm_prefork_module>
StartServers       20
MinSpareServers    20
MaxSpareServers   30
MaxClients  80
MaxRequestsPerChild   10000

3.4. Checking for Apache HTTP problems

"error.log" contains the error messages of Apache. For example to check for too many simulatanous request you can run.

grep MaxClients /var/log/apache2/error.log

// If there are problems you might get something like this:
// server reached MaxClients setting, consider raising the MaxClients setting 

3.5. Apache Configuration via .htaccess

Use the file ".htacess" to configure certain behavior of Apache HTTP. One major application of this file is to redirect URL to other URL's.

The following .htacess file reroutes that to It also redirect access to a certain webpage (/articles/SpringFramework/article.html) to another webpage via a 301 redirect. The 301 redirect will tell search engines that this side has moved and is the recommended way to move webpages.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.vogella\.de$
RewriteRule ^(.*)$$1 [L,R=301] 
redirect 301 /articles/SpringFramework/article.html 

3.6. Performance - Turn on gzip compression

To optimize the download time of your webpages you can turn on gzip compression. This require the Apache module "mod_deflate" which can be installed by the following command:

a2enmod deflate 
/etc/init.d/apache2 restart 

The compression can be activate via your ".htaccess" file.

# compress all text & html:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript 

4. Configuring virtual hosts in Apache

4.1. What are virtual hosts in Apache?

Virtual Hosts allow Apache2 to be configured for multiple sites that have separate configurations.

This allows you to have one Apache HTTP web server running on one IP serving multiple domains. Of course you still need to configure the DNS settings for the domains to map to the server but if you do this, you can

4.2. How to configure vhosts under Ubuntu

Under Ubuntu you create a configuration file in the /etc/apache2/sites-available folder, for example the


  DocumentRoot /var/www/vhosts/
  <Directory /var/www/vhosts/>
    Options -Indexes
    AllowOverride all
    Order allow,deny
    allow from all

  ErrorLog ${APACHE_LOG_DIR}/error.log

  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn

  CustomLog ${APACHE_LOG_DIR}/access.log combined
        CustomLog ${APACHE_LOG_DIR}/ combined


You enable sites (vhosts) with the following command.

#enable the vhost
sudo a2ensite

#disable the vhost
sudo a2dissite 

After enabling sites you have to restart your Apache HTTP server.

5. About this website

5.1. Donate to support free tutorials

Please consider a contribution Support free tutorials if this article helped you. It will help to maintain our content and our Open Source activities.

5.2. Questions and discussion

Writing and updating these tutorials is a lot of work. If this free community service was helpful, you can support the cause by giving a tip as well as reporting typos and factual errors.

If you find errors in this tutorial, please notify me (see the top of the page). Please note that due to the high volume of feedback I receive, I cannot answer questions to your implementation. Ensure you have read the vogella FAQ as I don't respond to questions already answered there.

5.3. License for this tutorial and its code

This tutorial is Open Content under the CC BY-NC-SA 3.0 DE license. Source code in this tutorial is distributed under the Eclipse Public License. See the vogella License page for details on the terms of reuse.

6. Links and Literature Apache HTTP Homepage