APACHE HTTP WEB SERVER RUNNING IN A VIRTUAL MACHINE
These are the steps needed to create an Apache HTTP web server running in a virtual machine.
First of all, grab some html code and edit it in Notepad to use as a test website.
Save it to your desktop as index.html
If you were to double click on this icon, your default web browser would fire up and the web page would be displayed:
This the best way to create and test your website before using it in your Apache HTTP server.
Now we want to save that as a file in an Apache server running in a virtual machine.
Download the Oracle open source virtualization software Virtualbox. Once that is up and running, go grab the open source Ubuntu Linux server LTS and save the .iso image on your desktop or burn it to a disc.
Start a new virtual machine in Virtualbox (“New”) and install (“Show”) the Linux server. When running through the configuration, install the LAMP packages. LAMP stands for Linux, Apache, MySQL and PHP.
Once installed, start up Ubuntu Linux server.
For the index.html file to be served from the correct target directory, we need to first get to the proper file location and then create a directory where the files will be saved. Once that is done, then at the $ prompt, we will start the nano editor in the file to be created and saved. The default directory where websites are served in Ubuntu Linux Server LTS 14.04 is /var/www. The default webpage is at /var/www/html/index.html.
cd var/www
We want a new directory to hold each of 3 separate websites:
sudo mkdir websites
Enter password
cd websites
sudo mkdir site1 site2 site3
Then change to the directory to hold the first website
cd /site1
This is a placeholder for a future project where we will use the virtual host mechanism in Apache server to host several websites at the same IP Address.
Now we want to start the nano editor and type in the test website. Be sure to use $ sudo nano to be able to save your work.
$ sudo nano
Enter your Ubuntu password
Then type in your HTML Code and save it as index.html using nano command Control O.
Then exit out of nano using nano command CTRL X.
To be able to see a webpage within your Ubuntu Linux server, you need a rudimentary web browser.
W3M is a good one.
Back at the initial log in:
sudo apt-get install w3m w3m-img
Enter password and once installed, check it by running w3m with a webpage URL such as google:
Now you can test localhost to see the default webpage:
$ w3m localhost
Now we can ping the saved file at site 1 to /var/www/websites/site1/index.html to get our website:
By moving the cursor to the link, and hitting enter, it will take us to the referenced website in w3m:
We can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server is by entering:
$ ifconfig
Then getting the IP Address:
Here, you see it under the main Ethernet interface eth0. By plugging in that IP Address: 10.0.2.15, it takes us to the default webpage.
So we know that the code is sitting there, now we need to be able to ping it from outside the Apache webserver from a host. To get out of W3M, hit Ctrl z:
In our later project we will edit the global .conf files to allow those outside the private network to access the webpage.
To check on which ports are open and are LISTENING, type:
$ netstats –an | more
You can see our instance of Apache server does not appear to be listening for all IP V4 IP addresses at tcp port 80. Thus, perhaps Apache server needs to be started or restarted.
To start, type in /etc/init.d/apache2 start
Or type in etc/init.d/apache2 restart
Now we are going to go to where webpages are kept, which is /var/www/:
$ cd /var/www/
Then you can list the files in there using the command ls-a:
So now we need to get the file we saved at /var/www/websites/site1/index.html and save it at /var/www/html/index.html [Note, your files may be saved at a different location]
$ sudo nano /var/www/websites/site1/index.html
Enter your password, then:
Save as /var/www/html/index.html
Enter: Ctrl O
Then edit to save at new location:
/var/www/html/index.html
Type Yes to Overwrite. Then check to see if your new website is there.
CTRL Z
$ clear
Then $ w3m localhost:
|