Adding CGI to Your Page

Important Note: Do not skip instructions on this page. Failure to follow the instructions of this page which likely make you become very lost. Take you time and be careful and the task will be completed much more quickyly.

This is by far the most complex of the three tasks we are attempting in this project because it requries you to get into details that I know you would rather avoid. However, the payoff is nice  and I can lead you through the steps. So as long as you follow along with me, this should not be too bad.

CGI are programs that are told to execute by your web page but which actually exist elsewhere. The elsewhere is very specific however and that is what we will be spending most of our time doing. In this part you are going to add a counter to one (or many of your web pages). The nice thing about the web counter is that it can be run independently from any and every web page you have.

Setting up things on storm

There are three parts to setting up an external CGI program on storm and this is not the fun part. Follow these direction very carefully and we will get it done right the first time. 

Creating a cgi-bin directory and a stats directory   


The first step you will need to do is to connect directly to storm. There is a program available on your desktop called Secure Shell Client we used it when we changed our passwords at the start of the web project.  This is a one time step that should even cover all future cgi programs that you might want to install.

Connect to Storm

To connect to storm you will need to use the SSH Secure Shell Client available on your desktop. If it is not on your desktop, you will need to download it. You can do this quickly by following these instructions . Note that you will be installing two programs. One is allows you to log into storm and make changes (it will be called Secure Shell Client). The other one allows you to transfer files (it will be called Secure File Transfer Client).
  1. Click on Quick Connect to get going

  2. Type in storm.cis.fordham.edu as the hostname and your username that we gave you as the username.

  3. Click Connect and type in your passoword

  4. Now you will be at a prompt where you can type the command given below.

Type each of the following commands precisely as described. After typing each command hit enter.

        1) cd public_html
        2) mkdir cgi-bin
        3) chmod 755 cgi-bin
        4) mkdir stats
        5) chmod 777 stats
 

Getting, modifying and placing your counter program

I am providing you with the cgi program but you will need to make some very small modifications to the file.

  1. Right click on this link to the count.cgi program  and save the file to your USB memory stick.

  2. Open up wordpad. The easiest way to get wordpad is to click on the Start menu, Select Run, and then type wordpad.exe

  3. Within wordpad, open the count.cgi file now located on your USB memory stick.

  4. Find the line near the beginning that reads $counterdir = "/home/staff/kinley/public_html/stats/";

  5. Change the "staff/kinley" part to be "students/username" where the username is the name we gave you for your storm account.

  6. Save the file and exit wordpad.

Transfer the file to storm

Now you will need to use another program available on your Desktop called SSH Secure File Transfer Client. Find this program and then open it.

  1. Click on the Quick Connect Button.

  2. Type storm.cis.fordham.edu as the host

  3. Type your storm username as the username

  4. Type your password when prompted

  5. The screen should be divided into two halves.

  6. On the left half, browse for your USB Stick until you can find the count.cgi file we worked on earlier.

  7. On the right half, find and click into the public_html folder

  8. On the right half, find and click into the cgi-bin folder

  9. Drag the count.cgi file from the left hand side to the right hand side

  10. Task completed and you can close this program.

Final fix Needed

As it turns out, the transfer has the potential to muck with you cgi program. To fix this is not hard but takes another connection like the one you did above.
  1. Connect back to storm using the SSH Secure Shell Client as you did above when you needed to enter in all of the typed commands.

  2. Type the following commands

  3. cd public_html

  4. cd cgi-bin

  5. dos2unix count.cgi

  6. chmod 777 count.cgi

  7. exit

Now you should be all set and when you complete the next step you will have a working counter.

Putting the counter on your web page.

Everything is now set to tell your web page to execute the cgi. All that you have to do is add the following code to your web page

<img src="http://storm.cis.fordham.edu/~kinley/cgi-bin/count.cgi?froggy">
With this line you will need to change kinley to be your username.

I can now use this same line on any page I want to keep a separate counter for, I only need to change the last word each time.

For example, If I want to put a counter on my main page I might put

<img src="http://storm.cis.fordham.edu/~kinley/cgi-bin/count.cgi?maincount">

and if I want to put it on my hobby page I might.

<img src="http://storm.cis.fordham.edu/~kinley/cgi-bin/count.cgi?hobbbycount">

Once you get a counter working than you are done the CGI part of the assignment. Be sure to publish your page and then verify that it works by opening the published page up with a web browser.

Return to Web Development III