Home
> Linux > Full Story
Installing
And Configuring Apache On Linux
Apache
is the most popular and preferred Web servers on the Linux
platform. Also, its one of oldest Web server developed especially
for Linux. What makes Apache so popular? Firstly, it's freean
excellent by-product of the open source movement. Secondly,
even though it's free, its matches any other commercially
sold Web server in terms of comprehensive documentation
or direct technical support. In fact, Apache is well-documented
and supported open source freeware that exist today. Not
to forget the fact that it is available on almost all platforms,
starting from AUX, Solaris, Linux to UnixWare (and even
Windows NT). This coupled with the ease of installation,
small download size (of about 2.9 MB) and availability of
source code makes it the most preferred Web server.
Here we shall first take you through installing Apache from
its packaged or precompiled form, then work on few scripts
that will help you to start, reboot, restart the server,
get under the skin and learn about the three ".conf"
files that form the heart of Apache, and finally go a bit
deeper by doing virtual hosting.
Installation
Basics
Apache can be downloaded at http://www.apache.org (its also
bundled along with Caldera eServer 2.3.1 available on the
Network Magazine CD). Download it to a directory of your
choice (/tmp in this case). After that, you can install
it in one of the default locations by the commands listed
below:
mkdir /etc/httpd
cd /etc/httpd
mv /tmp/apache_1.3.19.tar.gz /etc/httpd
tar -zxvf apache_1.3.19.tar.gz && cd /etc/httpd/apache_1.3.19
&& ./configure --prefix=/etc/httpd && make
&& make install
This untars the Apache file and configures it in accordance
with the distribution or platform that you are using.
These commands will install the Apache server in /etc/httpd
directory
Note: I have made some changes over here. Basic reason being,
once we untar (unzip) the file, we need to configure it
in accordance with the kernel version and distribution that
we are using. Since each distribution follows a specific
installation procedure, the commands listed below are general
commands that work for every distribution that exists.
.conf: Next Steps
Once the installation is complete, the files can be viewed
via /etc/httpd directory.
Go to the /conf directory and make sure that the following
files are present: httpd.conf, access.conf and srm.conf.
Some versions of Apache use the httpd.conf-distro as the
name to avoid conflicts. In such cases rename the files
with a .conf extension.
Make a list of the domain name, the IP address and the different
directories that the server shall point to. Over here we
are making use of an IP named 127.0.0.1 and domain name
as bahbah.com. Edit the /etc/hosts file and make the following
entry in it:
127.0.0.1 bahbah bahbah.com
This line resolves the hostname for the server. You can
test it by typing "ping 127.0.0.1"
Now change to /etc/httpd directory and edit the httpd.conf
file. This file forms the heart of Apache server. Though
there are comments included in the file itself, don't make
any changes unless you are sure what you are up to. Listed
below are some changes that are necessary to get the server
working.
Changing
The httpd.conf File
The first 50 odd lines shall have a list of the various
modules. Modules are small programs that help to build up
a fully functional server. Ranging from Custom 404 Error
Messages to SSI directives, one can configure them as per
requirement and even add their own modules if desired.
Going further down the file, one encounters the following
text statements:
ServerType standalone
Port 80
Keep the above settings as they are.
HostnameLookups on
This line resolves the IP address of the person to the domain
from which he/she is visiting. It adds itself to the "logs"
file and proves useful if you want to keep a track of your
visitors.
User nobody
Group nobody
One can add the Group/User name or number who will be starting
the httpd server.
ServerAdmin notice@bahbah.com
If anything goes wrong then an email is sent to the address
specified above.
ServerRoot /etc/httpd
Points to the location where the configuration, error and
log files for Apache are kept.
BindAddress *
Planning to use Virtual Hosts, then this option serves variety
of tasks. Though it can be set to a particular domain name
or IP, giving it a wild card just eases the task if you
plan to setup multiple hosts.
The remaining things are self-explanatory and should not
be changed. Changes should only be made once you encounter
the statement shown below.
ServerName bahbah.com
NameVirtualHost 127.0.0.1
Make sure that you are having a valid DNS name for your
host.
Other settings for StartServers, MaxClients should be kept
at their default values. These values are optimised for
a general server and making them too high or low shall affect
performance drastically.
Changing
The access.conf File
Modify the following lines access.conf file:
<Directory
/home/httpd/html>
AllowOverride None
order allow,deny
allow from all
<Directory>
<Directory
/home/httpd/cgi-bin>
AllowOverride None
Options ExecCGI
</Directory>
This points to the default html and cgi file storage location.
If you are using your server to host just one site, put
all your html/cgi files in the location mentioned above.
You can even change it to another location.
Changing
The srm.conf File
All external applications like Real Player, redirects, various
MIME types, language supports, programming languages like
PHP are handled by this file. It is best not to change its
default values. Just read it once to understand its functioning
but don't modify the file till you are comfortable with
Apache.
The above sections complete the configuration of Apache
server. You now needs to restart the server so that the
changes can take effect. The configuration file for the
same purpose is given below. Store it in your /etc/rc.d/init.d
directory.
Simply type "./httpd restart" and your server
shall restart with a OK status. On encountering any error
the server shall stop and give you the error and possibly
the line number.
Once the server is restarted you can check it by calling
it by its IP address or its own name.
lynx www.bahbah.com or lynx 127.0.0.1 should fetch you the
default Apache start up page. If you have put some other
file in the /home/httpd/html directory then that file shall
be shown.
Nothing's happening? Try "ping 127.0.0.1" and
it should give a successful status reply. If it's not then
probably you have not made an entry in /etc/hosts file.
From this moment, your machine is now a full-fledged Web
server. Any one who types the IP address or domain name
(bahbah.com) in this case shall be connected to your server.
You can view the various activities such as the pages viewed,
number of unique hits, error messages and other things by
having a look at your log files in the corresponding /logs
directory.
Source
code for httpd file
#!/bin/sh
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo -n "Starting httpd: "
daemon httpd
echo
touch /var/lock/subsys/httpd
;;
stop)
echo -n "Shutting down http: "
killproc httpd
echo
rm -f /var/lock/subsys/httpd
rm -f /var/run/httpd.pid
;;
status)
status httpd
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reloading httpd: "
killproc httpd -HUP
echo
;;
*)
echo "Usuage:$0 {start|stop|restart|status}"
esac
exit 0
Virtual
Hosting
Apache server also supports virtual hosting. Virtual hosting
allows you to host multiple domains on a single IP. In other
words you can use the same IP address to host various domains
such as bahbah.com, bah.com, blahblah.com to name a few.
Suppose we plan to virtually host the domains listed above.
For this we have to make changes to the /etc/hosts and the
httpd.conf file.
The /etc/hosts file should bear the following look:
127.0.0.1 bahbah bahbah.com
127.0.0.1 bah bah.com
127.0.0.1 blahblah blahblah.com
Add the following listing at the end of httpd.conf file
located at the /etc/httpd/conf location
<VirtualHost
127.0.0.1>
ServerName www.bahbah.com
DocumentRoot /www/bahbah #This points to the location of
storage of html and other files corresponding to
bahbah.com.
Errorlog /www/bahbah/errorbahbah.log #Error messages are
stored over here.
</VirtualHost>
Restart the server and you can now access two domain names
with a single IP.
What we have done over here is configured our server to
listen for a specific IP 127.0.0.1.
Say a person enters http://www.bahbah.com in his browser.
His machine shall then resolve to a specific IP address
and try to connect to 127.0.0.1. On connecting to 127.0.0.1,
if it is acting as a dedicated server, it will serve the
required files else it will have a look at /etc/hosts file,
then at httpd.conf file and display only those files that
are relevant to the request.
Network Magazines prime audience is networking professionals
in both the industry and user organisations; Articles addressing
MIS managers, network specialists, CIOs, etc would be given
preference.
The articles should be solutions oriented covering technology,
applications or business. They should be specific and in-depth.
Articles should not be less than 1,000 words. They should
be accompanied by diagrams, illustrations, photographs,
etc., wherever possible. If word length exceeds than 3,500
words, the artic may be carried in parts.
Articles that look at practical issues are preferred. Good
examples make your write-up more meaningful. If you wish
to write about a theoretical issue, it should be a new one.
Case studies are welcome. Prominence must be given to the
existing system, challenges that were encountered and solutions
arrived at with the new implementation.
Besides the regular columns, each issue will have a special
focus on specific topic of relevance to the Indian market.
The technical features should talk about concepts and not
be company or product-specific.
We welcome information about new products and new services
introduced by your organisation for our Shelfspace and Newsfront
sections.
Rather than sending us your article right away, send us
an e-mail giving title of the article, its synopsis and
approximate word count. This will ensure that your efforts
are not wasted.
In e-mail communications, please use ASCII text format and
avoid document attachments as far as possible. Pictures,
illustrations, etc should be sent only as eps
or tiff file formats. A hard copy output of
the article can be couriered across.
Articles may be edited for clarify, style, relevance, etc.
Please give your name, designation, company name and e-mail
address along with the article.
You are welcome to send your photograph. Preferably in colour,
postcard size and with a good contrast.
Send in your contribution to:
The Editor
Network Magazine (The Indian Edition)
Business Publications Division,
Indian Express Newspapers (Bombay) Limited,
1st Floor, Express Towers, Nariman Point, Mumbai - 400 021.
Tel.: 202 2627 / 285 1964 Fax: 230 1007 / 202 2139
e-mail: sandzone@yahoo.com
Anurag Phadke can be reached at cbca@mantraonline.com