You are on page 1of 19

NUST SEECS PAKISTAN

APACHE
WEBSERVER
INSTALLATION
&CONFIGURATION

ASIM SALEEM
HASEEB AHMAD
DEPARTMENT OF ELECTRONCS ENGINEERING
Outline

 Introduction to ubuntu
 Introduction to Apache2
 Installation of apache
 Some Features
 Activating the User's public_html Directory
 Domain Mapping
 Creating Virtual Directory

Objective

Our objective of this project is the installation of apache2 on Linux (ubuntu) and configures
it. We have tried to implement as more as possible functions of apache2 web server.

Introduction to UBUNTU

Ubuntu is a free, stable, and secure OS. Ubuntu comes at a tempting price and provides many
of the advantages of popular commercial operating systems such as Windows and OS X. But
it also has potential drawbacks — manual installation and possible compatibility issues.

Ubuntu is an operating system developed by a worldwide community of programmers and by


employees of Ubuntu's commercial sponsor, Canonical. Ubuntu is based on the concept of
free or open-source software, meaning that you do not pay any licensing fees for Ubuntu, and
you can download, use, and share the operating system free of charge.

As it is Linux-based operating system, Ubuntu has a well-deserved reputation for stability


and security. Historically, Linux has proven itself to be a workhorse server operating system,
and this is where, up until now, it has been most widely used and best known.

However, in recent years, Linux has also become valuable on desktop and laptop computers,
making it an option for individuals and businesses. Ubuntu is generally known to be the most
widely used version of Linux available. Because the software is free to download and share,
it is difficult to track exact usage numbers.
Introduction to Apache2

Apache is a web server application that has a played a major role in the growth and
continuous development of the web. It is a free open-source solution, which backs up most
popular operating systems including Microsoft Windows, Linux, Unix, Mac OS X and
Solaris. Apache is the most widely installed server application on the web since 1996.

Historical Perspective

The first version of the Apache web server was created by Robert McCool, When McCool
left NCSA in mid-1994, the development of httpd stalled, leaving a lot of patches for
improvements circulating through e-mails. These patches were provided by a number of other
developers besides McCool: Brian Behlendorf, Roy Fielding, Rob Hartill, David Robinson,
Cliff Skolnick, Randy Terbush, Robert S. Thau, Andrew Wilson, Eric Hagberg, Frank Peters
and Nicolas Pioch.

According to the Apache Foundation, the name was chosen out of respect for the Native
American tribe of Apache (Indé), well-known for their endurance and their skills in warfare.
However, the original FAQ on the Apache Server project's website, from 1996 to 2001,
claimed that "The result after combining [the NCSA httpd patches] was a patchy server. The
first explanation was supported at an Apache Conference and in an interview in 2000 byBrian
Behlendorf, who said that the name connoted "Take no prisoners. Be kind of aggressive and
kick some ass". Behlendorf then contradicted this in a 2007 interview, stating that "The
Apache server isn't named in honor of Geronimo's tribe" but that so many revisions were sent
in that "the group called it 'a patchy Web server'". Both explanations are probably appropriate
though the pun explanation has fallen into disfavor.

Version 2 of the Apache server was a substantial re-write of much of the Apache 1.x code,
with a strong focus on further modularization and the development of a portability layer, the
Apache Portable Runtime. The Apache 2.x core has several major enhancements over
Apache 1.x. These include UNIX threading, better support for non-Unix platforms (such as
Microsoft Windows), a new Apache API, and Ipv6 support. The first alpha release of Apache
2 was in March 2000, with the first general availability release on April 6, 2002.
Apache Rocks

Apache is a highly configurable Web Server with a modular design. It is very


easy to extend the capabilities of Apache Web server. Anyone with decent C or Perl
programming expertise can write a module to perform a special function. This means
that there are tons of Apache modules available for use.
Apache is a free, open source technology. Being free is important but not as
important as being open source.
Apache works great with Perl, PHP, and other scripting languages. Most Web
applications are still scripts. Perl excels in the script world and Apache makes using
Perl a piece of cake with both CGI support and mod_perl support.
Apache runs on Linux and other Unix systems. Linux used to be an underdog
operating system, which has now found itself in enterprise computing arena. Linux
and Apache go hand-in-hand in the enterprise world today. I believe Linux’s
acceptance in the business world has made Apache’s entry into such territory easy.
However, there are people who would argue that it was Apache’s fame that made
Linux find its way into the business world easier. Either way, Apache and Linux is a
powerful combination. Other Unix systems such as FreeBSD and Solaris, and the new
Mac OS X also play a great role in expanding Apache’s user base horizon.
Apache also runs on Windows. Although Apache will run much better on Windows
platform with version 2.0, Apache was already in Windows market with Version
1.3.x. We will see a lot of Windows systems switching to Apache from Microsoft
Internet Information Server (IIS) because Apache 2.0 architecture gives it the power it
needed to compete natively.

Some of the new features include:

Unix Threading: Apache has the ability to run a hybrid multithreaded mode in Unix servers.
This process improves scalability for most configurations.

Multiprotocol Support: This features allows Apache to act as a platform for protocols other
than HTTP, enabling a machine to go far beyond the traditional web server.

Enhanced Support for Non-Unix Systems: Apache 2 is more stable and much faster on
other platforms such as Windows, which tends to perform better with Microsoft server
applications.

Filtering: The new filtering feature allows modules to be written as filters that can act on
streams of data sent to and from the server. For example, CGI scripts can be parsed for SSI
(server side include) directives by using the INCLUDES filter. The module filter enables
external programs to function in same manner that allows CGI programs to act as handlers.

Multilanguage Error Response: With Apache 2, SSI documents are used to send error
response messages to the web browser in various languages. These messages can be easily
customized by the system administer to get a consistent look and feel.

Easy Configuration: Most of the confusing, complex directives of the original Apache have
been simplified in version 2.0. The Server name directive gives the name of the server and
only the port number for redirection and virtual host recognition.

Unicode Support for Windows NT: On Windows NT, Apache 2.0 uses the native Unicode
for the encoding of all filenames. This enables the application to provide multi-language
support for all Windows NT systems including 2000 and XP.

Updated REL: Apache 2.0 is integrated with the Perl compatible Regular Expression
Library based on the powerful syntax of Perl version 5.

lunarpages is one of many providers who realize that Apache 2.0 is the server platform of the
future. With all the features mentioned above and others such as IPv6 (Internet Protocol
version Six) support and multi-user administration, Apache 2 has proven to be a reliable
workhorse more than able to meet the demand of today’s World Wide Web.

Uses

Apache is primarily used to serve static as well as dynamic Web pages on the World Wide
Web. Many web applications are designed expecting the environment and features that
Apache provides.

Apache is the web server component of the popular LAMP web server application stack,
alongside Linux, MySQL, and the PHP/Perl/Python (and now also Ruby) programming
languages.

Apache is redistributed as part of various proprietary software packages including the Oracle
Database or the IBM WebSphere application server. Mac OS X integrates Apache as its built-
in web server and as support for its WebObjects application server. It is also supported in
some way by Borland in the Kylix and Delphi development tools. Apache is included with
Novell NetWare 6.5, where it is the default web server. Apache is also included with many
Linux distributions.

Installation of Apache

System Requirements
Apache runs on just about any platform in use today, including Linux; FreeBSD; OpenBSD;
NetBSD; BSDI; Amiga OS 3.x; Mac OS X; SunOS; Solaris; IRIX; HPUX; Digital Unix;
UnixWare; AIX; SCO; ReliantUNIX; DGUX; OpenStep/Mach; DYNIX/ptx; BeOS; and
Windows.

Here are some methods to install apache2:

Compiling and Installing Software from Source


We download a file that contain all the source code for the application we want to install,
unpack it, and compile it on our system. Compiling is a process that turn the source code into
an executable binary code. It is a fairly straight forward process, and we find that a lot of
software we install will need to be built from source.

Installing RPM's using the Redhat Package Manager


It is a flexible and easy method to install this software. Software installed from this method
differs from compiling from source in a few ways, but the most important is the software is
already compiled for us. Essentially we are just doing extracting the pre-built binaries and
copying them to their pre-selected destination. RPM's are the files that have ".rpm" extension.
The downside to RPM's is that we don’t have as much choice about where software is
installed on our system, how it is compiled, and how it is configured.

Installing software with Apt-get (used by ourselves)


APT (Advance Packaging Tool) is a package management system. It consists of different
tools, which names usually begin with "apt-”: apt-get, apt-cache, apt-cdrom, etc. apt-get
handles dependencies resolution and takes care of downloading the software for us.

Though apt-get is generally used to install binary packages, it also can build and install
source packages. One can further more ease the process of installing software by using
Synaptic.
apt-get depends on Debian packages repositories that can be configured in the file
/etc/apt/sources.list. A typical Debian stable sources.list would look something like this :

#Local Mirror
deb ftp://ftp.us.debian.org/debian/ stable main contrib non-free
deb-src ftp://ftp.us.debian.org/debian/ stable main contrib non-free

#Security Updates
deb ftp://ftp.us.debian.org/debian-security/ stable/updates main contrib non-
free
deb-src ftp://ftp.us.debian.org/debian-security/ stable/updates main contrib non-
free
Once the user has a sources.list adapted to his/her needs, the local list of packages needs to
be updated :

apt-get update

To search a package from its text description :

apt-cache search <something>

Replace <something> with an application name or word. For example,

apt-cache search irc client

will display a list of several irc clients.


Installating a binary package is done in one single step :

apt-get install apache2


Installing Slackware Packages
Slackware packages are usually .tgz files containing pre-built binaries. To install software in
slackware we will need to find and download the .tgz package manually. If we are looking for
a slackware package and have not found it yet, we should search Linux packages for it.

Some Features
Start Apache 2 Server
This command will restart the apache server. It is required when we stop the server due to
some reason and want to start it again.

# /etc/init.d/apache2 start
Similarly apache can be restarted or stopped by using the same commands with a little bit
change in itself.

Restart Apache 2 Server


# /etc/init.d/apache2 restart

Stop Apache 2 Server


This command will stop the apache server.

# /etc/init.d/apache2 stop
Document Root
It is a directory (a folder) that is stored on host's servers and is designated for holding web
pages. When someone else looks at your web site, this is the location they will be accessing.

Its path is /var/www

In order for a website to be accessible to visitors, it must be published to the correct directory,
the "document root."

Activating the User's public_html Directory


On systems with multiple users, each user can have a web site in their home directories
known as public directory.

We have installed apache2 web server and now we activate user public directory. We create a
directory (folder) called "public_html" in our home directory,

root@asim-laptop:~# mkdir public_html


When we have a web server shared by many people, like a shared-hosting ISP, it is necessary
to give each user separate access to the "live" files. I have found that on a simple
development machine, it is also easier to have our work all within our own home directory
and not have to worry about permission and folders owned by the root user. What it gets you
is the ability to access your websites in your home directory by a URL in the form
http://localhost/~myhome.

There are only two commands we need to enter to activate the User Directory feature, and
then one command to restart the apache server. The last command includes an absolute path,
so it doesn't matter where we execute it from. The first two "ln" commands assume we are in
the directory /etc/apache2/mods-enabled. What we need to do is create two symbolic links
(soft links, symlinks) in the stated directory pointing to the corresponding module in
/etc/apache2/mods-available (which is where they really live). So, if "$" is your prompt,

me@myhost$ cd /etc/apache2/mods-enabled

me@myhost$ sudo ln -s ../mods-available/userdir.conf userdir.conf

me@myhost$ sudo ln -s ../mods-available/userdir.load userdir.load

me@myhost$ sudo /etc/init.d/apache2 restart

Open up a browser and type http://localhost/~asim, where "asim" is our username. Apache
should show the folders and files we have in our directory, or even display a web page if we
have an "index.html" file in there.
Saving files outside:
Files that can be downloaded from our web site can be saved outside the public_html folder.
It is necessary in case we want to allow downloading for registered users only. In such case
we should set the access right of the files to registered users and we should save the files
outside the public_html folder, so only registered users can access it.
If we are using linux server and our path to public_html folder is e.g.:

/usr/home/ username/public_html

then our path will look like the following path:

/usr/home/username/

Domain Mapping
Def.
The Domain Mapping allows user to use a custom domain name instead of the standard
domain name.
Now we will map the domain of localhost.
First of all, open apache’s main configuration file, name /etc/apache2/apache2.conf. A
search for the word virtual brings us to the following line:
Include /etc/apache2/sites-enabled/[^.#]*
This mean that when starting apache, it will look for files in /etc/apache2/sites-enabled/.
We go there and see what is in.

$cd /etc/apache2/sites-enabled/

$ls -l

total 1

lrwxrwxrwx 1 root root 36 2005-12-27 01:42 000-default -> /etc/apache2/sites-


available/default

This only links to the file in directory /etc/apache2/sites-available/. We might wonder what
the point in doing such is. Well, this simply allows us, mainly when we are using our box as a
web server.

Now we want to to map the domain name dev.haseeb.com to our local machine, using the
code file in /home/myuser/public_html/haseeb.com/.

While in /etc/apache2/sites-available, create a new file (let say Haseeb.com.conf)


Now add the following lines in this file:

<VirtualHost dev.example.com>

ServerAdmin webmaster@localhost
#We want to be able to access the web site using www.dev.haseeb.com or
dev.haseeb.com

ServerAlias www.dev.haseeb.com
DocumentRoot /home/myuser/public_html/haseeb.com

#if using awstats


ScriptAlias /awstats/ /usr/lib/cgi-bin/

#we want specific log file for this server


CustomLog /var/log/apache2/haseeb.com-access.log combined
</VirtualHost>

Now, we specified a new host to apache but it is not yet linked to the repertory where apache
actually looks for virtual hosts. Let go to:
$cd /etc/apache2/sites-enabled/
and create a link to the file we just created:
$sudo ln -s /etc/apache2/sites-available/haseeb.com.conf

Now apache is almost ready to restart, but before doing so, we must inform our linux system
that dev.haseeb.com and www.dev.haseeb.com are not to be looked for on the net, but on the
local machine instead.
To do so, simply edit /etc/hosts and add the new host names at the end of the line beginning
by 127.0.0.1, which is localhost.
In the end, our file should look like:

127.0.0.1 localhost.localdomain localhost dev.haseeb.com www.dev.haseeb.com

And now we are done, simply reload apache:


sudo /etc/init.d/apache2 reload

Open our web browser and enter the following address dev.haseeb.com. It runs the same as
when we were using http://localhost
Creating Virtual Directory
A virtual directory offers a way to provide a consolidated view of user identity without
constructing an entire directory infrastructure.
It receives requests and directs them to the appropriate data sources. When the user data
comes back, the directory provides the data to the appropriate application as all the data had
been stored in one place. The feature to reach into native disparate repositories makes virtual
directory technology ideal for combining data stored in a distributed manner.
Now we made a virtual directory /asim for physical path
/home/asim/public_html/haseeb.com/test

Open the /etc/apache2/conf.d/asim file for edit.

sudo gedit /etc/apache2/conf.d/asim

We edit the asim file. Say we want to create virtual directory named asim with the folder
/home/asim/public_html/haseeb.com/test. Then we have to add the following lines in the asim file

Alias /asim /home/asim/public_html/haseeb.com/test

<Directory /home/asim/public_html/example.com/test>
DirectoryIndex index.html
Options FollowSymLinks
AllowOverride None
order allow,deny
allow from all
</Directory>

Restart apache

sudo /etc/init.d/apache2 reload


Now we have created a virtual directory named as “asim” for
/home/asim/public_html/haseeb.com/test

References

http://www.linuxforums.org/forum/linux-tutorials-howtos-reference-material/64958-
how-install-software-linux.html
http://www.mybestratedwebhosting.com/best-web-hosting-tips/introduction-to-
apache-2.html
http://en.wikipedia.org/wiki/Apache2
http://www.techsoup.org/learningcenter/software/page7858.cfm
http://www.linuxforums.org/forum/linux-tutorials-howtos-reference-material/64958-
how-install-software-linux.html
http://forums.opensuse.org/applications/404662-how-start-stop-apache2.html
http://www.cyberciti.biz/faq/ubuntu-linux-start-restart-stop-apache-web-server/
http://kimbriggs.com/computers/computer-notes/linux-notes/apache2-public_html-
virtual-directories.file
http://techgurulive.com/2009/02/21/how-to-configure-virtual-hosting-using-apache-2-
on-ubuntu/
http://www.aitechsolutions.net/apacheredirect.html
http://tipsntricksbd.blogspot.com/2009/06/how-to-create-virtual-directory-in.html
http://ubuntuforums.org/showthread.php?t=28184

Books:
Apacheserver2bible by Mohammed j. Kabir

You might also like