Virtual Machine & WebServer Tutorial

Introduction

The purpose of this guide is to give complete instructions on how to create a Virtual Machine that runs a Web Server along with a DNS server. The Web Server will allow us host a web-facing website. The DNS server will allow us to use a domain name to access the website.

Part 1: Virtual Machine

First we will create our VM (Virtual Machine). We will use Debian as the OS for our VM which is a unix/linux system.

1.1: Creating the VM

VirtualBox is a tool used to both create and run VM's. We will use this to create and run our Debian OS.

1.1.1: Downloading VirtualBox

After downloading VirtualBox for your respective OS, running Virtual Box should look as follows:

1.1.2: Downloading Debian

We will also need to get our Debian installation from debian.org.

1.1.3: Debian Installation Settings

Click "New" and type in a name for the VM. Click "Next".

The remaining steps may remain default until arriving at "File Location".

Click the small green arrow on the right side side; select "File System" then "Scratch"; click "Save"; click "Save" again; click "Create"

Click "Settings" so that we can configure the installation for our purposes.

Under "system", under "Boot Order" check "Network". Click "Netowrk" in the left hand column. On "Attached to" selet "Bridged Adapter". Click "OK".

Click the green Start Arrow. Click "Start".

Hit Enter to start installation. Use default settings until reaching "Configure the Network". Set "Domain Name" to your own domain. Use tab to select "continue".

At the "Choose a mirror" prompt, scroll to the top and select "Enter information manually". Change the mirror to the the Debian OS downloaded from 1.1.2.

set root password and take note of it for later use. Create your used id and password. Select your time zone.

When prompted about the disk partition, choose "Guided - Use entire disk". Use the defaults until asked to write changes to disks. Select "yes" and continue. Use defaults unless changing installation options at your own discretion.

Our VM will complete installation and then reboot. We now have a working Virtual Machine running Debian.

1.2: Configuring the Virtual Machine for the WebServer

Before installing our Web Server, we need to confirm that our network interface is configured properly.

/etc/network/interface vi /etc/network/interface

This command will allow us edit our Network Interface configuration. "vi" may be replaced with your editor of choice, "vi" is included in many OS's however while using Debian, "nano" may be preferable. We need our network interface configuration to look as follows:

/etc/network/interface auto lo iface lo inet loopback iface eth0 inet static address 192.168.180.10 netmask 255.255.255.0

Part 2: Apache WebServer

2.1: Installing Apache

First we will run the command in terminal to install Apache. It is as follows:

Installing Apache apt-get install apache2

This will install Apache with default configuration.

If you open a web brower (IceWeasel is shown below), and direct the URL to "localhost", you should now see Apache's default "It works!" page to confirm that it is working.

2.2: Configuring Apache WebServer

2.2.1: creating the directories

We need to create the directory that will be served by apache.

Apache Directory mkdir /ourdirectory mkdir /ourdirectory/oursite

Part 3: DNS Server

3.1: Install Bind

Bind is a popular option for running a DNS server on Linux. The installation command is similar to installing Apache:

Installing Apache apt-get install bind9

This will install Bind with default configuration.

3.2: Network Configuration

3.2.1: NIC configuration

DNS requires a static IP address, so the "etc/network/interface" file must be configured properly (see: 1.2).

Don't neglect to restart the NIC after making changes to the configuration. This is easily accomplished with the following commands:

Restarting NIC ifdown eth0 ifup eth0

3.2.2: /etc/resolv.conf

This file must be editted so that the nameserver is our VM's address and the domain and search entries are local domain.

3.3: Edit the DNS configuration

Using Terminal, change the directory to "/etc/bind" and edit the following file, replacing "ourdirectory" and "ourdomain" with your respective directory and domain. Also replace the IP address with the IP address set in 1.2

/etc/bind/zones.1918 zone "ourdirectory.ourdomain" { type: master; file "/var/cache/bind/db.ourdirectory.ourdomain" };

zone "50.168.192.in-addr-arpa" { type: master; file "/var/cache/bind/db.192" };

Note that the IP address in the second zone is reversed.

3.4: Create and Edit Zone Files

Using a Root Terminal, we must edit the following file to look as follows (again, replacing "ourdirectory", "ourdomain" and the IP's with your own data from above):

/var/cache/bind/db.ourdirectory.ourdomain $TTL 1d ourdirectory.ourdomain. IN SOA ns1.ourdirectory.ourdomain. root.ourdirectory.ourdomain. ( 2007102701 ; 3h ; 15 ; 1w ; 3h ; ) ourdirectory.ourdomain. IN NS ns1.ourdirectory.ourdomain.

ns1.ourdirectory.ourdomain.uncc. IN A 192.168.50.128 www.ourdirectory.ourdomain.uncc. IN A 192.168.50.128 debian.ourdirectory.ourdomain.uncc. IN A 192.168.50.128 kerberos.ourdirectory.ourdomain.uncc. IN CNAME debian.ourdirectory.ourdomain. ; ;Sub-domain ; www.us.ourdirectory.ourdomain.uncc. IN A 192.168.50.128 ftp.us.ourdirectory.ourdomain.uncc. IN CNAME debian.ourdirectory.ourdomain.

We also need to edit the second zone file to look as follows (Again, note the reversed IP address.):

/var/cache/bind/db.192 $TTL 1d 50.168.192-in-addr.arpa. IN SOA ns1.ourdirectory.ourdomain. root.ourdirectory.ourdomain. ( 2007102701 ; 3h ; 15 ; 1w ; 3h ; )

50.168.192.in-addr.arpa. IN NS ns1.ourdirectory.ourdomain. 128.50.168.192-in-addr.arpa. IN PTR www.ourdirectory.ourdomain.

3.5: Test DNS Server

Using Terminal, entering the command nslookup <IP address> and replacing the IP address with your own should yield results similar to as follows:

nslookup 192.168.141.10 Server: 192.168.141.10 Address: 192.168.141.10#53

10.141.168.192.in-addr.arpa name = www.ourdirectory.ourdomain.

Part 4 (optional): Host site on Heroku WebServer

Heroku is a service that provides a free WebServer and is intended to help provide both development and production environments for webapps. For the purpose of this guide we will be serving just a simple, static, one-page site so much of the powerful features that Heroku provides will be unused.

4.1: Installing Git and Heroku Toolbelt

Download both Git and Heroku Toolbelt. This will allow for us to use git and heroku in tandem to push our changes to our heroku app on the heroku servers. Consult their respective documentation sets to learn more. Both are powerful and flexible tools.

We must first create an app using the heroku dashboard to link to our local repository containing the site. We will use a combination of git and the heroku-toolbelt to accomplish this.

Heroku does not support serving a simple html page immediately as it's intended to be used for powerful and scalable node.js, ruby, or php web-apps; but a simple trick will allow us to serve a static html page using a simple line of php.

Create a new file named index.php with just the following line:

<?php include_once("home.html"); ?>

This will cause Heroku to identify the directory as a php application though the only php used is a direction to display our static home.html page.

Summary

If this guide is effective and has been followed until the end, we should now be able to build a Virtual Machine and also able to run a Web Server as well as a DNS server to serve a web-facing internet directory. This would allow for limitless applications all of which may be internationally broadcast for any purpose. This is possible without your own VM/Webserver; however the benefits of maintaining your own should not be overlooked: most notably that it's a relatively inexpensive way to have more control over your own data at a deeper level.