Today we continue with networking. In this lab we will configure Apache to handle multiple domains, and install a simple Perl script to support Web chat.
Other protocols are permitted in a URL, such as https (secure HTTP access), ftp (access a file on an FTP server), and others. Not all are recognized by all browsers, but they are still considered valid to the URL specification.
A request of this kind is made for every separate object on a page (often, including the body of the page, every image and advertisement, sometimes for JavaScript, sometimes for CSS, and for AJAX activites).
You can see all the activity by running wireshark while visiting a web page like Google Maps.
In our installation, apache has been installed as /usr/sbin/httpd with configuration and logging in /etc/httpd. First, start apache by modifying the services on your machine as we did in last lab (e.g., in System->Administration->Services) to start httpd and make it start at boot. Open a web browser, and visit http://localhost/. You should see a Test page for Apache. Now you know your httpd server is running.
Now let's create some content. The default home directory for Apache's content is in /var/www/html/. Note that it is empty! The test page you saw was generated on-demand by a module (see the info on the test page for details). If you create an index.html file (which is the default file that is served, even when only the root of a directory is specified as the URL), it will show up instead of the test page.
Create two subdirectories (choose your own names, such as alpha and beta). Within each subdirectory, create new index.html files (we want to have two different files here). You might visit some website you like and use the browser's Save As menu to make a copy of the HTML.
Create two hostnames that map to your localhost. You can do this by modifying (if necessary) the zone files you created in last lab, or by just adding two new hosts into your /etc/hosts file and have them both map to 127.0.0.1. To test this, you should be able to use these hostnames in your web browswer, and still get the Apache/Fedora test page.
Now we can create virtual Web sites for each of these hostnames. Near the end of Apache's long configuration file is a section called VirtualHost. You'll want to enable virtual hosting by uncommenting the NameVirtualHost directive (just above) and specifying the IP address to which it applies (use whatever one you used in your zone files or /etc/hosts file above). Copy the sample twice and modify the copies to match the two hostnames and two directories that you created above. Restart apache, and you should now see the host-specific index.html home pages rather than the test page with your Web browser. However, if you want to have a default host other than your first virtual host, you'll need to create a third entry (to go first). (If no Host: HTTP header is included in a request, or doesn't match an existing VirtualHost entry, the Web server will serve using the first VirtualHost that matches.)
Fortunately for this exercise, Apache is already configured to support CGI scripts. The default directory for them is /var/www/cgi-bin/. As a demonstration of using a Perl script for CGI, we will use a simple chat application called EveryChat. Check out the local installation at http://wume.cse.lehigh.edu/~brian/chat/chatframes.html so that you know what to expect.
Download this free (but obsolete) application from http://www.everysoft.com/ and use unzip to uncompress this zip archive and extract its contents. Take a look at the readme.txt file --- it has instructions on how to install EveryChat, and those instructions include needing to edit multiple files. This package was written on a Windows machine, and so all of the files are written with DOS-style end-of-line markers (carriage return -- ASCII 13) rather than UNIX end-of-line markers (newlines -- ASCII 10). For text and HTML this might not matter, but it sometimes matters for scripts. If you have problems running the Perl script, you may need to translate the format. I used the dos2unix utility; there are likely other methods. The package documentation does not mention this (potential) problem.