User Tools

Site Tools

//[lab source : NSRC]//

1 Apache and Virtual Hosts Exercises

1.1 Install Apache version 2

Apache is already installed on your machines, but if it was not you would simply do:

apt-get install apache2

As the root user. Once Apache is installed it is up and running. The startup defintion for Apache is /etc/init.d/apache2. You can stop, start, restart, reload Apache by doing:

# service apache2 stop
# service apache2 start
# service apache2 restart
# service apache2 reload

1.2 Configure Virtual Hosts in Apache 2

1.2.1 Directory Structure There are several ways to approach virtual hosting. The first thing you must determine is your directory structure where each web site will reside. For our purposes we will use the standard Linux convention of:


1.2.2 Multiple Names All of your PCs have DNS entries for their assigned IP addresses on the Authoritative nameserver for the zone – that is on & Thus, you can use: -> 192.168.30.X

to access your machines. We will take advantage of this for the exercise.

1.2.3 Web Directories Let's create the web directories that we’ll need:

# cd /var/www/
# mkdir

Be sure you replace “X” with the number of your PC.

1.2.4 Index Files Now let's create a HTML file to our directory:

# vi

Put the following html code:

<title>Apache2 Ubuntu Default Page: It works</title>
<h1>bdNOG5 Linux Workshop<h1>
<h2> Virtual Host<h2>

Close and save the file.

1.2.5 Apache Configuration Files Now we need to adjust the Apache configuration files for our two new sites. We will treat the site as our default site – that is, where people arrive if, for some reason, the come to our box without specifying a host name (for instance, if they use an IP address instead):

# cd /etc/apache2/sites-available
# vi 000-default.conf

In the file default we will change the “DocumentRoot” setting to point to the directory for Look for this line:

DocumentRoot /var/www/html

Change this line to read:

DocumentRoot /var/www/

Save the file and exit. Now let’s restart Apache and see if the server is still working:

 # service apache2 restart 

In a web browser (on your machine) open the URL” and you should see:

bdNOG5 Linux Workshop Virtual Host

1.3 Log Files Apache logs are under /var/log/apache2 folder. Go through the access.log & error.log for better understanding.

bdnog5/track2agenda/web-service-lab.txt · Last modified: 2016/04/03 17:01 by Fakrul Alam