Web Perl  «Prev   Next»

How to run CGI Program - Exercise

Below are the questions you need to answer before you can run a CGI program. Make note of what you find out and send it to us by pasting your notes in the text area at the end of this page. That will serve as the results of this exercise for you, and it will also help us to assist you should you have any problems running your CGI programs later on in the course.

  1. Are you allowed to run CGI programs on your server?
    If not, you will need to either obtain permission, or set up and run a server on your own computer. An excellent solution to this problem is to get a simple inexpensive PC (even an old discarded 486 or 386 will suffice), and load
    1. Linux and the
    2. Apache Web server on it.
    This configuration will be plenty fast for your local testing purposes (in fact, with a Pentium it will be as fast or faster than most servers on the Internet today), and if you are not already familiar with Unix, it will be a valuable experience to install it and set it up.
  2. What is the location of the Perl interpreter on your system?
    If you are using Unix, will need to make sure that the "#!/usr/bin/perl" line in the program agrees with this location, or it will not work.
    If your system is not Unix-based, you will also need to find out what procedures are necessary to run Perl with CGI on your system. You will probably need to remove the "#!/usr/bin/perl" line from the top of the Perl script, and run a special container for the Perl interpreter.
  3. What directory do you need to put your CGI program in? This will be different for every server.
  4. What filename restrictions are there for CGI programs?
    Some servers that allow CGI programs in the document tree, require that their filenames end in ".cgi". You will need to find out about this.
  5. What permissions or attributes need to be set for your CGI program to execute?
    In Unix, it is usually sufficient to use:
    chmod 755 filename
    
  6. What is the URL to access your CGI program?
    This will depend on the answer to 3 and 4. If you must put your CGI program in a special "cgi-bin" directory, the URL will probably be something like "http://www.yourserver.com/cgi-bin/hello.cgi"
Perl CGI Scripting
Installing Linux and Apache can be an adventure in itself, especially if you are not familiar with Unix. Our tutors will do their best to answer questions, if they are able, but please remember that this course is about Perl and CGI, not installing new operating systems. There are many places you can go for help, and we will direct you to them as best we can. DistributedNetworks is not responsible for any problems that may arise as a result installing a new operating system on your computer. Answering these questions before you try to run your first CGI program will alleviate 90% of the problems most first-time CGI programmers experience. Paste your notes about setting up your server in the text area below and click Submit when you are finished.