Apache Configuration In this exercise, we are going to get Apache configured to handle a couple of different websites. We are just going to use localhost (the default address for a server), but the same process would be applied if you were creating real websites. Web servers are really nothing more than an application that points to the correct folder when someone enters the web address. So in other words, if I enter fred.localhost (my web address), the Apache server points to a folder that I created in the default directory that contains the website s files for display. This is why you can have multiple websites hosted on one server; you just have multiple folders, with each web address pointed at the appropriate one. 1. Start linux 2. Make sure apache is running by opening a web browser (such as Firefox) and pointing it at localhost. It should come up with a page that says It works!. If that does not come up, open a terminal window and start apache by typing: /etc/init.d/apache2 restart and hitting enter, then repeat the above test. If it still does not work, make sure that you followed the instructions to install Apache correctly, or contact me with any error messages you see. 3. Open Terminal by hitting Ctrl-Alt-T, then type su and then enter, and then type in your root password. 4. Type: cd /var/www/ and hit enter 5. Type: mkdir LastnameFirstinitial and hit enter (for example, tripps. *note I use all lowercase because linux is case sensitive and that way I don t need to remember what I capitalize. Use whatever naming scheme you prefer (all lowercase, all uppercase, InterCap format. Whatever you choose, stick with it. ) 6. Type: mkdir fred and hit enter 7. Type: nano /var/www/lastnamefirstinitial/index.html and then enter, and type the following, inserting the appropriate folder name where indicated. Do the same thing for nano /var/www/fred/index.html. Save each file as index.html in the appropriate folder by hitting ctrl-o, and then exit with ctrl-x. <html> <head> <title>(insert folder name here, for example, Fred )</title> </head> <body> <p>hi, I m in the (Insert folder name here) folder</p> </body> </html> 8. Now open your browser. Go to https://localhost:10000 to get into Webmin, and sign in as root. (If it comes up with a security warning, tell it to trust this site from now on.) 9. Expand the Servers section by clicking on the green arrow next to it, then select Apache Web server. This should bring you to the screen pictured below:
10. Make sure the Existing Virtual Hosts tab is selected, and click on Default Server. 11. This will bring you to the screen pictured below:
12. We are now going to change the default server directory to point to the folder called lastnamefirstinitial that you created (in my case, tripps). Click Document Options 13. Change the Document Root Directory to /var/www/lastnamefirstinitial and also change directory options from default to selected below. In the option list, change server-side includes and execs and server-side includes to yes (see screen below) 14. Also change the virtual server path to /var/www/tripps (you will need to scroll down to see the setting)(see below). When you have done that, hit Save, then return to server index. 15. Repeat steps 9 through 14 with the Virtual Server that appears directly underneath the Default server. This is the initial Virtual Server; it should say Handles the name-based server on address * in the description for it. 16. Click the link in the upper right corner that says apply changes. Keep in mind that changes you save never take effect until they are actually applied. To apply the changes, stop apache using the stop apache link up in the upper right hand corner, then Start Apache again. Since Apache is being restarted, be aware that applying changes will cause a brief disruption in service to any websites being hosted on that machine. 17. In your browser, open a New Tab. In the address bar, type: localhost then hit ENTER. It should go to the page you created for your lastnamefirstinitial folder. For the lab, free your mouse from the Linux environment, click on the top of the Linux window, then hit ALT-PRNT SCRN to take a screenshot of the browser pointing to localhost and your page displaying in the browser. Paste this into a Word (or other word processing program) to upload for the lab. (*NOTE: If you have trouble with the Linux window wanting to take the screenshot instead of Windows, try using the Windows Snipping Tool (found under Accessories). Then get back into the Linux environment by clicking in the window. If Linux also takes a screenshot, just hit cancel and don t save it.
18. Now we will set up our virtual server for our fred directory. Go back to your Webmin tab, then to the main Apache Webserver Window, then click on the Create Virtual Host tab. 19. The only things to change are to point Document Root to /var/www/fred/, and change the server name to fred.localhost. Change the copy directives from: Nowhere to Automatic: 80 (/var/www/yourlastnamefirstinitial) (see screenshot below) 20. Hit the Create Now button. 21. Apply the Changes 22. Click Apache Webserver again so you see the list of servers available. Click on the Virtual Server for the fred.localhost address. Scroll down to the bottom of the page where it lists Virtual Server Details. Change the Port to 80 (see screenshot). Save, Apply Changes, and Stop and Start Apache.
23. Now we need to tell the server where to find our new virtual server. Under normal circumstances for a real site, you would go to whoever hosted the DNS records for your domain (oftentimes whoever you purchased your domain name from), and point the domain name to the IP address of your server (or the IP address of your firewall, which you would then direct to forward any traffic on port 80 to the internal network IP address of your server). In our case, we are going to use the hostnames file to tell it where fred.localhost is, because the server always consults the hostnames file first before looking a site up in the DNS system. So, in the left hand menu expand Networking and click on Network Configuration (see screenshot)
24. Click on the Host Addresses icon. It will bring you to a screen similar to the one below:
25. Click on Add a new host address ; on the screen that comes up, put 127.0.0.1 as the IP address, and fred.localhost as the Hostname. (see screenshot). Once you have done that, hit the Create button. 26. Once back at the host list, you should see your new entry at the bottom. Click the Return to network configuration link. 27. Once at the main Network Configuration menu, click the Apply Configuration button. This will take a moment as it restarts. 28. Open a new tab in your browser, and try entering fred.localhost in the address bar. It should now go to the page you created for the fred directory. 29. As you did above, take a screenshot of the browser showing the address fred.localhost in the address bar with the fred page displayed and paste it into the same word document you used for the last screenshot to send to me for the lab.