Web Perl   «Prev  Next»

Running CGI on your Server - Exercise

Running a CGI program on your server for the first time can be a real adventure. Be comforted in the fact that when you have done it once (and documented the steps you took), it will be a lot easier the next time.
As you go through this process, make a checklist of the steps you take and paste them in the text area at the end of the exercise. This will allow you to more easily duplicate your steps in the future, and it will allow us to more easily help you, should you have any problems later on.
Enter the Hello World program in a text editor on your local computer.
If you are using Mozilla and choose to cut and paste the code from your browser window, you may notice odd line breaks added to the code that break the CGI.

#!/usr/bin/perl$CRLF = "\x0d\x0a";
print"Content-Type: text/html$CRLF$CRLF";
print"<H1>Hello, World!</H1>\n";

Plain Text Editor

Be sure to use a plain text editor, and not a word processor, to enter the program. Word processors tend to add a lot of formatting information to their files, which is great for word processing but will probably cause the Perl compiler to complain loudly and incoherently. Tell us what editor you are using.
  1. Send the program over to the server. Unless you entered the program with an editor right on the same machine your server runs on, you will need to send your CGI program over to your server. Usually you will do this with an FTP client.
  1. If you are running Unix, you are in luck because the ftp command will probably work for you.
  2. If you are running on a Windows machine, try WSFTP
    (If your server's host machine is not also running an FTP server, you may need to find another method of getting your program over to your server. Check with your system administrator if this is your situation.)

ASCII or Text mode

Make sure that you select the ASCII or Text mode for your transfer. If you send a Perl script in binary mode from one operating system to another, you may run into incompatibilities with the way the two systems deal with end-of-line characters. The ASCII or Text mode of the FTP system will convert line endings for you.
  1. Now that you have transfered your program over to your server, make sure that you set any permissions that are necessary according to the instructions you gathered in the "" exercise.
  2. Determine the URL of your CGI program based on the information you gathered in the last exercise. Now enter it in your Web browser. You should see something similar to the image below.

During the "Dotcom era", Netscape was a popular browser. This exercise can be executed using 1) Chrome, 2) Edge, or 3) Firefox.
hello cgi program running on netscape
"Hello cgi" program running on Netscape (Legacy)

If your server is publicly available on the Net, provide the URL of your working program here in addition to the checklist of steps you have created. Otherwise, just paste in the checklist. Click the Submit button when you are finished.