Using and Troubleshooting CGI Scripts
All Unix web hosting accounts that support a domain name will allow you to install and use your own CGI scripts.
Keep in mind that using CGI scripts and CGI programming are a lot more involved than HTML, and require a basic understanding of file permissions, directory structure, Unix commands and programming in languages like Perl or C. If you are new to web development, or do not have these skills, we suggest using some of the pre-installed CGI scripts that are available.
CGI Script Usage
- Here are some guidelines and tips for using CGI scripts with your Unix web hosting account.
- The name give to your CGI scripts must have the extension .cgi (for example, search.cgi, mail.cgi, etc). The extension .cgi tells the server that the file should be processed as a CGI script. If the file extension used for your script is .pl, you will need to rename your script before it will work.
- CGI scripts can be placed in any sub-directory within your public_html directory. They do not need to be placed in a directory named cgi-bin. If the directions for your CGI script say to place the script in your cgi-bin directory, you can place the script in any sub-directory within your public_html.
- Do not create a directory in your public_html named cgi-bin. The cgi-bin directory is a special system directory that contains pre-installed CGI scripts, and cannot be used as a sub-directory to store your own CGI scripts. If you want to make a directory for your CGI scripts, we suggest using the name cgibin.
- Make sure that you set the proper permissions for your scripts. Users must be able to read and execute your script. This can be done by telnet using the command "chmod 755 script.cgi", or by FTP (if your FTP software supports this).
- If your script is written in Perl, the first line must be configured to tell the script where Perl is located. The first line of your script should read:
- The location of the sendmail program on the server is:
- Usually, CGI scripts need to have some configuration done that includes the path to your directory. To configure your CGI script, you will need to determine your home directory.
- If you need to edit a CGI script, you must use a simple text editor (like Notepad or SimpleText). You cannot use a program like Microsoft Word or WordPerfect.
- Never upload CGI scripts in BINARY transfer mode - always upload CGI scripts in ASCII transfer mode. Even if your FTP software has an "automatic" setting, it's best to force it to upload in ASCII for CGI scripts. When a CGI script is uploaded using the wrong transfer mode, you will get a "500 Server Error".
- If your script needs to write to certain directories or files, make sure that the permissions are set to allow this. Normally, a CGI script would include directions telling you what the permissions should be set to. A Unix / CGI Script Permissions Guide is available if you need more information.
- If you need to run CGI scripts as your own username, you can use a CGI wrapper to run your scripts. The wrapper installed for you is called cgiwrap.
When installing a CGI script, there are usually problems. Each CGI script is different and requires different settings, and even the pros have problems.
By far, the most common error you will get when trying to set up a CGI script is a "500 Server Error". This error means that there is something wrong with the internal workings of your script. Here are the most common problems/solutions: