YOU ARE HERE: Home > Tutorial > Tutorial > Article

Install and Use Apache Web Server
By Jack Xu This article was not rated yet.
 
Printer Version Printer Friendly | Add As Favorite | Link to Article

About the Author

Jack Xu has worked in IT for 12 years. He is a senior system architect for large distributed web portals. He has also developed Java based forums and search engines.

Apache web server is the most popular web server that has been used nowadays. It is free, open source, and can work with other web application servers.

In this tutorial, I am going to show how to install and use this web server.

Install Apache

You can download apache from apache web site http://httpd.apache.org/

For unix/linux, you should download httpd-2.0.54.tar.gz

For windows, you should download apache_2.0.54-win32-x86-no_ssl.msi

In this tutorial, we assume you use apache on windows, because most people have windows operating systems on their computers.

After download apache_2.0.54-win32-x86-no_ssl.msi file, you may download its PGP signature and MD5 checksum. Verify downloaded apache server using GnuPG and md5 software to ensure the integrity of apache server. For details of how to verify PGP signature and MD5 checksum, see tutorial article ?Verify the signature of downloaded files? on http://www.usanlyst.com tutorials section.

Suppose you have verified the signature of apache_2.0.54-win32-x86-no_ssl.msi, double click this file would start the installation. If all the default installation options are chosen, the server will be installed at C:\Program Files\Apache Group\ Apache2 folder.


The ?bin? subdirectory hosts apache executables and corresponding library files. In windows, the executable is Apache.exe and ApacheMonitor.exe files. Apache.exe is used to start apache server, while ApacheMonitor.exe is used to start Apache service monitor.

The ?conf? subdirectory includes all the files that are used to configure apache server.

The main configuring file is httpd.conf file.

Server Basics

In httpd.conf, you will find import variables that define the server.

1. ServerRoot : ServerRoot defines where most of apache server files are located. It is usually the folder where the apache web server installed. In our case it is C:\Program Files\Apache Group\ Apache2. Look in the httpd.conf file, you can find a line: ServerRoot "C:/Program Files/Apache Group/Apache2"

2. DocumentRoot: DocumentRoot defines where Apache server (httpd) check for html files. In our default installation, it is the folder htdocs. Look in the httpd.conf file, you can find a line: DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs".

3. ServerName: ServerName gives the name and port that the server uses to identify itself. The httpd.conf file includes ServerName: name:port. If you have not registered a domain name, use IP address for the name. Http port can be set to 80 or 8080. For example: ServerName: 127.0.0.1:80

4. ServerAdmin: Your address, where problems with the server should be e-mailed. This address appears on some server-generated pages, such as error documents.
ServerAdmin: support@doctorcares.com

5. LogFiles: Logfiles, including error log, log level, Transfer log, log format and custom log , are defined in main configuration file also.

6. Dynamic Shared Object (DSO) Support: Apache web server can be used with other modules. The main configuration file load modules using statements, for example
LoadModule alias_module modules/mod_alias.so
LoadModule cgi_module modules/mod_cgi.so

7. Listen: Allows you to bind Apache to specific IP addresses and/or ports. For example: Listen 80


Virtual Hosts

Apache can be configured to host multiple web sites. Apache uses both IP-based virtual hosts and name-based virtual hosts.

In the case of IP-based virtual hosts (your machine may have multiple several physical network connections), the following lines are added to the main configuration file:

List 1. IP-based virtual hosts


<VirtualHost 192.168.1.300>
DocumentRoot /app1/usanalyst/www
ServerName www.usanalyst.com
ServerAdmin demo@www.usanalyst.com
ErrorLog /app1/usanalyst/logs/error_log
TransferLog /app1/usanalyst/logs/access_log
</VirtualHost>

<VirtualHost 192.168.1.301>
DocumentRoot /app2/getusjobs/www
ServerName www.getusjobs.com
ServerAdmin demo@www.getusjobs.com
ErrorLog /app2/getusjobs/logs/error_log
TransferLog /app2/ getusjobs /logs/access_log
</VirtualHost>

Explanation

We have configured two IP-based virtual hosts, www.usanalyst.com that runs on the IP address 192.168.1.300, and www.getusjobs.com that runs on 192.168.1.301.

We have explained the meaning of DocumentRoot, ServerName, ServerAdmin, ErrorLog and TransferLog in the ?Server Basics? section.

If one types http://usanalyst.com, he/she will see web site www.usanalyst.com from IP address 192.168.1.300, from corresponding DocumentRoot /app1/usanalyst/www.

If one types http://www.getusjobs.com, he/she will see web site www.getusjobs.com from IP address 192.168.1.301, from corresponding DocumentRoot /app1/getusjobs/www.


In the case of Name-based virtual hosts, we need add definitions in Line 2 to the main configuration file.

Line 2. Name-based virtual hosts


NameVirtualHost 64.103.2.3:80

<VirtualHost 64.103.2.3:80>
ServerName www.usanalyst.com
ServerAlias usanalyst.com *.usanalyst.com
ServerAdmin demo@www.usanalyst.com
ErrorLog /www/usanalyst/logs/error_log
TransferLog /www/usanalyst/logs/access_log
DocumentRoot /www/usanalyst

</VirtualHost>
<VirtualHost 64.103.2.3:80>
ServerName www.getusjobs.com
ServerAdmin demo@www.getusjobs.com
ErrorLog /www/getusjobs/logs/error_log
TransferLog /www/ getusjobs /logs/access_log
DocumentRoot /www/getusjobs
</VirtualHost>

Explanation

Name-based virtual hosts can use one IP address represent multiple domain names. In List 2, we set up virtual hosts for two domains www.getusjobs.com and www.usanalyst.com with one IP address. When one clicks http://www.usanalyst.com , the Apache web server uses /www/usanalyst as the document root where web pages are located. When http://www.getusjobs.com is clicked, /www.getusjobs becomes document root where web pages are located.


Server Security

Let?s discuss how Apache handle securities.

On many systems, you would have an entry in its configuration file that looks like


<Directory /etc/httpd/cgi-bin>
Oprions -Indexes FollowSymLinks
</Directory>

In this case, it means in directory /etc/httpd/cgi-bin, user cannot retrieve indices created by the server, and httpd (Apache server) will follow symbolic links.

Directory directive can be used control the access priority to it. For example, the entry below


<Directory /etc/httpd/cgi-bin>
<Limit>
Order deny, allow
deny from all
allow from getusjobs.com usanalyst.com
</Limit>
</Directory>

allows access to /etc/httpd/cgi-bin folder from domain getusjobs.com only.

You may restrict file access by adding entries using File directive,


<Files ~ "\.(SAV|sav)$">
deny from all
</Files>

Apache also allows user based access control

<Location /Admin>
Allow from usanalyst.com
Require group admins
Require user jack
Satisfy Any
</Location>

Above allows user jack or users from admins group access folder /Admin, or users access from domain usanalyst.com

For more information of security settings for apache, one can refer to the Apache reference manual.

Use Apache

In windows, under the folder of DocumentRoot, we create folder tutorial. And create a web page helloworld.html. We put this file in the folder tutorial (C:/Program Files/Apache Group/Apache2/htdocs/ tutorial in my instllation).

<html>
<header><title>Hello World</title></header>
<body>
<h3>Hello World</h3>
</body>
</html>


When type http://localhost/tutorial/helloworld.html in a web browser such as IE 6 or Netscape 8, you will see a page like

Summary

In this tutorial, we demonstrated how to set up a web server and use configuration file for multiple virtual hosts. We also show how to set security to guard files in apache server. Apache server can host static contents. We will talk how to use it with web application servers in next tutorial.


Was this article helpful to you?yesno

Related Publications
 
A quick way to create grids in Photoshop
Struts Tile Tutorial
Using Axis SOAPMonitor
How to fix RedHat 9 ftp server problem
Use Apache with Web Application Server
Install and Use Apache Web Server
Verify the signature of downloaded files
Quick tutorial about finding MAC address of your PC
HIPAA Introduction (Part 2)
HIPAA Introduction (Part 1)

(Registered users can post questions/comments)

 
 TLINKS SEARCH
Advanced Search
Help
 Recommended Links
Red Cross
Responding to hurricane katrina relieve. Donate today. It's a Great Feeling to Help.
http://www.redcross.org
Getusjobs.com
Getusjobs.com is the job site focused on American jobs. See the results that put us on top.
http://www.getusjobs.com
Database Tool
TLinkSoft® tools empowers developers, integrators and DBAs to be more productive.
http://www.cppunit.org/download.jsp
USAnalyst.com
USAnalyst.com provide a community for database analysts, business analysts, developer analysts and managers.
http://www.cppunit.org/article

Powered by Tlinks Systems