CGI Help - How to Edit CGI Files

Quick jump to Uploading and Changing Permissions to CGI Scripts

CGI stands for Common Gateway Interface and it's usually written in a format called a script.  These scripts are commonly used to run guestbooks, message boards, chat rooms, games, etc.   The great fact about CGI is that if you learn how to install one script, you'll be able to install almost any one you want.

There are three basic steps involved with getting a script to work:

1) Find and download the one you want
2) Edit the script where necessary (per the instructions)
3) Upload the script to your web site

PLEASE READ:  Most of the free web site providers do NOT give access to a cgi bin.  The best thing to do is to register your own dot com name and find a hosting company that supports CGI.

First, you need to become familiar with uploading (saving) files and changing permissions via your FTP program.  Or perhaps your web hosting company will allow you to upload files through their control panel. Either way, you MUST become familiar with transferring files to your web server.

You will also need access to a cgi bin. A cgi bin is nothing more than the folder on your web server where the cgi files will sit.  This access is also granted by the web hosting company.

If you do have access, you should already have a folder called "cgi-bin" somewhere on your server. Some web hosting companies may call it something slightly different so be sure to double check with them before you begin uploading scripts. If you do not have a folder on your server, but you know you have access to a cgi bin, then you can create the folder on your own.

Create the folder either by using your FTP program or by using your web hoster's control panel.

Now that you've identified your cgi bin, you're ready to find a script, edit it, and then upload it to your web site for your use.

Where Do I Find These Scripts to Download?

My favorite site is  They have a variety of free cgi scripts for message boards, chat rooms, guestbooks, games, banner rotations, and so much more.

Visit the site and find the script you want (Check in the PERL section for CGI scripts).  Download the necessary files and open the "help" (or readme) file that is included.  This will give you specific instructions on what files you need to edit to get the script to work.  Remember, every script may be slightly different.

Things You Should Know Before Editing The Scripts

1. Always open and edit CGI scripts in a basic text editor (Notepad, for example). CGI scripts are really no different than normal text files that usually end with either .cgi or .pl They are written in ASCII format, and can be opened and viewed using any text editor. Don’t ever use an HTML editor to edit or save CGI scripts.

2. You’ll need to know the path to Perl on your web host. Almost all scripts will ask you for the path to PERL. Simply ask your hoster what this is. It is usually something like…




3. The Path to Your Site. This is NOT the same as the URL or address of your site. For example, the URL to your site is probably something like, but the path is the "stuff" behind the www that you cannot see with your naked eye.

So the path to your site may be something like: /home/docs/YourSite/www

Which would make the path to your cgi bin something like: /home/docs/YourSite/www/cgi-bin/

Again, make sure you ask your hoster about this. Please don’t try to just copy this and hope that it works. It is likely that your path is totally different.

4. More You May Want to Know

Let’s say you have a message board that has an email function. For example, every time a new post is made, you, the administrator will receive an email. The CGI script may ask you the path of your server's mail program (ie: /usr/lib/sendmail )  

Again, you can obtain easily by asking your web host provider.

Once you've figured all these things out, it's a matter of opening the cgi file using your text editor,and filling in the blanks whenever the program says so. It may say "change the below to the path of your CGI-BIN."

What do you do then? 

Put in /usr/local/etc/httpd/sites/ , or whatever your CGI-BIN's path may be.

"Okay, I Think I Got It….But Can You Walk Me Through Installing a Script on My Site?"


Let’s say you want a guestbook on your site where visitors can leave you their name, email address, and a message for you about your site. 

You could go to and search the PERL scripts for a free guestbook script and download it from there. Remember PERL is the language the CGI scripts are usually written in. So don’t get confused if you see PERL scripts. These are what you need.

Once you find one you want to use, download and unzip the files that are needed to make the guestbook work, you’ll have to edit some of the files. (Check the readme or instructions file that came with the scripts) There will be one or more cgi files that you’ll have to edit to make the script work properly.

Simply open the file you need to edit in Notepad and follow the instructions. Usually there will be some variables at the beginning of the script that you’ll need to define. For example, they might ask you for the "Path to your CGI bin" By now you’ve asked your hoster for this information so you put it in the spot provided.

Most CGI scripts already have a "dummy" path included so you can see the general format. Make sure you pay attention and see if you should include the / (backslash) or not.

CGI scripts are not forgiving.  If you have any strange or extra characters included, you may cause the script to fail.  So make sure you follow the instructions carefully.

Once you’ve defined all the variables asked for in the script, then you can upload these files to your cgi-bin using either your FTP program (we recommend WSFTP) or your hoster’s control panel.

For info on how to upload using WSFTP, click here.

Uploading Your CGI Scripts and Changing Permissions

Most scripts tell you where to upload the scripts and the permissions you’ll need to give each file. Make sure you follow their instructions.  You also may be asked to create additional folders on your server.

"Why Do I Need to Change Permissions?"

CGI scripts are installed on the server end, and if the wrong person were to access them, it could cause damage to your site and possibility even the server. (Your hoster wouldn’t be too happy about that) That's why you need to set permissions on your CGI script before they will be allowed to run. And don’t worry…if the permissions are set incorrectly, you’ll know it because the script will not run.

For example, if you are installing a guestbook or a message board, users will need to have access to WRITE to certain files, but only be able to READ others.  If you didn't give them WRITE access, then they wouldn't be able to add new entries to your book.

How to Change Permissions

  1. Open WSFTP and upload the files to the appropriate folders on your server. (Follow the script’s instructions). Make sure you are uploading any file that ends with .cgi, .html, or .pl in ASCII format. Graphics, however, should be uploaded in BINARY. If you’re using WSFTP then you’ll see the option to switch between the two right in the middle of the program’s interface. Select the appropriate bubble.

  2. After you have uploaded the files, check your script instructions and find out the permissions that should be set for the files. Highlight the file you need to change and right click it. Choose "chmod" and then a pop-up box will appear.

The most popular permission settings are 755 and 777. To set the file to 755, check every box except the "Write" box for the "Group" and "Other" row and hit "OK".  See image below.

To set the file to 777, check every box and hit "OK".  See image below.

If you’re asked to set the permissions to any other number then here’s how to figure out which boxes to check:

Each box represents a number.

The READ box = 4

The WRITE box = 2

The EXECUTE box = 1

Each number in a CHMOD value represents a column. So if you were asked to set a file to 664, the 6 refers to the Owner column, the 2nd 6 refers to the Group column and the 4 represents the Execute column.

So to set the file to 664, you would check the READ and WRITE boxes in the "Owner" column (4 + 2 = 6) Then you’d check the READ and WRITE boxes in the "Group" column (4 + 2 = 6). And lastly check the READ box in the "Other" column (4).

Now that you’ve edited the cgi files, uploaded them, and set all the permissions, your script should be ready to rock and roll! If you receive errors when trying to run it, then it could be:

  1. You have not uploaded all the files to the proper folders
  2. Some permissions are not set correctly
  3. You’ve incorrectly defined some of the variables in the cgi script (i.e. the path to your cgi-bin, etc. Make sure you ask your hosting company if you're not sure about paths.)

Be sure to consult the documentation that came with the script and double check you have done everything that was asked of you.

So if you can grasp the basics of editing and installing CGI scripts, you should be able to tackle almost any script that you want to use. Now you’ll be able to install message boards, games, chat rooms, and so much more.

If you liked this, please share. Thanks!