Configuring The Apache Web Server

Submitted by abhishek on Fri, 04/18/2008 - 16:58

What is the Apache Web Server?*

  • is a powerful, flexible, HTTP/1.1 compliant web server
  • implements the latest protocols, including HTTP/1.1 (RFC2616)
  • is highly configurable and extensible with third-party modules
  • can be customised by writing 'modules' using the Apache module API
  • provides full source code and comes with an unrestrictive license
  • runs on Windows 2003/XP/2000/NT/9x, Netware 5.x and above, OS/2, and most versions of Unix, as well as several other operating systems is actively being developed
  • encourages user feedback through new ideas, bug reports and patches

adapted from www.apache.org

Download The Apache Source from www.httpd.apache.org

Current Stable Version available Apache 2.2.6

Requirements

Disk Space:
Make sure you have at least 50 MB of temporary free disk space available. After
installation Apache occupies approximately 10 MB of disk space. The actual disk space
requirements will vary considerably based on your chosen configuration options and any thirdparty modules.

ANSI-C Compiler and Build System

Make sure you have an ANSI-C compiler installed. The GNU C compiler (GCC) from
the Free Software Foundation (FSF) is recommended. If you don't have GCC then at least make
sure your vendor's compiler is ANSI compliant. In addition, your PATH must contain basic build
tools such as make.


Configuring & Installing Apache
Download From http://httpd.apache.org/download.cgi
Extract # gzip -d httpd.2.2.6.tar.gz
# tar -xvf httpd.2.2.6.tar
# cd httpd.2.2.6

Configure # ./configure –prefix=PREFIX
Compile # make
Install # make install
Test # PREFIX/bin/apachectl start

PREFIX must be replaced with the filesystem path under which the server should
be installed. If PREFIX is not specified, it defaults to /usr/local/apache2.
PREFIX = /apache is used in this document from here on
Starting & Stopping the Apache Server

1. Starting # /apache/bin/apachectl start
2. Stopping # /apache/bin/apachectl stop
3. Restarting # /apache/bin/apachectl restart

Configuring the Apache Server
Server Side: httpd.conf

This is the primary configuration file. It traditionally contains configuration settings for
the HTTP protocol and for the operation of the server. This file is first processed

Client Side:

There is as such no configuration required in the client side the only requisite is that the
client should have a browser such as Mozilla Firefox or Links installed and should be able to
connect to the network.

Important Directives of the httpd.conf
1) ServerName
2) Server Root
3) Server Admin
4) Document Root
5) Listen
6) User / Group
7) Include
8) Directory
9) Directory Index
10)Alias / Script Alias
11) Virtual Hosts
12)User Directory

Sample Configuration File (httpd.conf) with explanation of each Statement/Directive/Block
Apache Version Apache 2.2.6
Apache is installed/configured in /apache
Location of HTML pages /home/user/apachedocroot/htdocs
Location of CGI-BIN /home/user/apachedocroot/cgi-bin
Port 80
IP Address 192.168.10.3

# Sample Configuration file httpd begins
ServerRoot “/apache”
// Server Root is the top of the directory tree under which configuration, error and log files are kept.

Listen 80
// This statement allows apache to bind to specific IP address or Port No

ServerAdmin [email protected]
//Server Admin is the mail address of the Server Administrator this address is used in some of the server generated pages such as error documents

ServerName www.server.com:80

// is the name and port that the server uses to identify itself
// Server Name is usually the registered DNS name of the host in case there is no registered name specify the IP Address


User apache
Group www


//It is usually a good practice to create a dedicated user and group for running httpd
//httpd is first run as the root user and then it automatically switches

DocumentRoot “/home/user/apachedocroot/htdocs”

//This is the directory which contains the documents (HTML files etc) by default all requests are taken to this directory


Options FollowSymLinks
AllowOverride None
Order allow, deny
Deny for all


// Each directory to which apache has access can be configured individually at first we should configure the
//default to be very restrictive



Options Indexes FollowSymLinks
AllowOverride None
Order allow, deny
Allow from all


// Under this block we are configuring the directory which contains the main documents
// Options varies for directory depending on its contents and can be any combinations of
// “None”, “All”, Indexes, FollowSymlinks, SymLinksifOwnerMatch ExecCGI
// AllowOverride controls what directives may be placed in .htaccess file it can be
// “None”, “All”, FileInfo, AuthConfig Limit.
// Order & Allow controls who should get access to files in a particular Directory


DirectoryIndex index.html


// This tells apache which file to look for when a directory is accessed


ErrorLog logs/error_log

// Specifies the location of errorlog file


ScriptAlias /cgi-bin/ “/home/user/apachedocroot/cgi-bin”

// Script Alias controls which directory contain the Scripts, when www.server.com/cgi-bin/ is called for, it searches for scripts in /home/user/apachedic/cgi-bin

//Virtual Host Section
//Virtual Host can be of 2 types 1) Name Bases 2) IP Based (Server using more then one NIC)

NameVirtualHost 192.168.10.3

//Usually the IP Address in used in place of name for making virtual hosts


DocumentRoot /www/example2
ServerName www.example.org


//Declaration of a Name Based Virtual Host when www.example.org is requested from the server it displays the content of /www/example2 the end user never knows from where the content came. was it from the same server or from a different one this is only possible when a strong DNS exist in the server to resolve names to IP addresses.

# IP-based


DocumentRoot /www/example4
ServerName www.example4.edu


//Declaration of IP Based Virtual Host. Apache Web Server can also listen to more then one IP at a time and is able to differentiate between the requests coming to it using the above configuration it provides different content to different IP's


UserDir public_html
UserDir disabled root

AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

Order allow,deny
Allow from all




//User Directory Module, Used to specify the directory of each user which could be used as users Document Root inthe above configuration public_html directory in each users home is declared as his Document Root when a user requests for www.server.com/~username the server forwards the request to the public_htnl directory of the user.

Please Note:
Firewall should be configured in a way that clients can get access to port 80 of the server