website served from apache server in a vitual machine v.2 web viewwe can also access the default...

27
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: 1

Upload: dangnguyet

Post on 01-Feb-2018

220 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

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:

1

Page 2: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

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.

2

Page 3: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the 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.

3

Page 4: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

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:

4

Page 5: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

Now you can test localhost to see the default webpage:

$ w3m localhost

5

Page 6: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

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:

6

Page 7: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

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.

7

Page 8: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

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:

8

Page 9: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

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.

9

Page 10: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

To start, type in /etc/init.d/apache2 start

10

Page 11: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

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:

11

Page 12: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

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

12

Page 13: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

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

13

Page 14: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

Type Yes to Overwrite. Then check to see if your new website is there.

14

Page 15: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

CTRL Z

$ clear

Then $ w3m localhost:

SUCCESS.

Now we need to be able to let others access this website from outside the server.

First I note that when I fire up Firefox outside the Virtualbox virtual machine that is holding the Apache server, I am not able to access the website 10.0.2.15.

I check the IP Address of the host machine (as assigned by DHCP) and it is 192.168.1.72

These are on 2 different subnets. So we need to assign the VM a static IP Address in the same subnet, 192.168.1.150

15

Page 16: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

Right now DHCP is assigning the IP Address. We want to change that to a static IP Address using nano.

$ sudo nano /etc/network/interfaces

Now we can edit this file:

16

Page 17: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

Need to save using CTRL X and yes to overwrite and Enter

Now we need to restart apache2:

$ sudo /etc/init.d/networking restart

Test the webpage by entering in new IP Address.

$ w3m 192.168.1.150

No joy. So I looked at the Virtualbox settings. I changed this:

17

Page 18: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

To this:

Did Restart again:

18

Page 19: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

Still no joy, so I shut down the VM and started it up again:

19

Page 20: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

And success. The moral, don’t get discouraged, keep trying until you find the answer to the problem at hand.

As you can see, the new IP address information has taken effect.

Now we can test again using w3m:

20

Page 21: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

21

Page 22: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

22

Page 23: Website served from Apache Server in a Vitual Machine v.2 Web viewWe can also access the default webpage by going to 127.0.0.1. Finally, we can see what the IP address of the server

Finally, now to test outside the webserver (effectively, a host outside the webserver). Fire up a web browser outside of Virtualbox and enter in the new static IP address—here 192.168.1.150:

SUCCESS.

23