CGI (Common Gateway Interface) is a process used by the server to pass information between the user and an application on the server. With CGI access, you can install Perl scripts on your website for such things as feedback forms, guestbooks, counters, and so on. Increasingly though, these functions are being managed by PHP instead.
CGI scripts must be run from the cgi-bin directory which is outside the main web directory. CGI scripts need to have a .cgi or .pl extension. PHP scripts need to have a .php extension.
For security purposes, we use Apache’s suEXEC for the execution of CGI scripts. The exact paths you need to use depend on the hosting type, the server your site is on, the type of script etc. Please contact support if you need path information for scripts on your site.
If you upload files to a sub-directory, you would be able to view them by typing in http://www.yourdomain.com/sub-directory/filename.ext (replace these with the relevant names).
Here are a few things to try when you are troubleshooting a CGI script:
1) First of all, thoroughly read through the instructions that came with the script and also check the website where the script was sourced for troubleshooting info and user forums.
2) Make sure that you have uploaded your script to your cgi-bin which is outside your public web directory.
3) Check to see if the script was uploaded to the server in the proper format (usually ASCII not binary). If uploaded in the wrong format the script may appear to be in the right place but will not execute.
4) Make sure that there are not any DOS/Windows carriage returns (i.e. ^M) at the end of each line in the script. This is usually caused by a text editor or FTP program that is not properly uploading your script in a Unix/Linux format. If this is happening, try changing your code line break settings or upload settings to Unix/Linux.
Here’s how this is done in Dreamweaver: From the menu, go to Edit > Preferences > Code Format, then change Line Breaks to “LF (Unix)”.
5) Check the script to make sure the magic comment specifies where perl is located: #!/usr/bin/perl
6) Verify that all the paths are correct, including your public directory path. Do not use the “www” part of your domain in your public directory path.
7) Check to see if all the file permissions are set correctly. Permissions can be set using an FTP program that allows permissions to be set on transfer. Typically scripts are set to be 755, user: read, write, execute; group: read, execute; other: read, execute (-rwxr-xr-x), but you should always check your script instructions or README to be sure.
PLEASE NOTE: For security purposes, within the cgi-bin, script permissions cannot be set higher than 755, or user: read, write, execute; group: read, execute; other: read, execute (-rwxr-xr-x).
8) If you have checked all the above and are still receiving an “Internal Server Error” when trying to execute the script, this can occur when the script is uploaded or when the script is edited and saved in certain text editors. Usually the file is corrupted with the (line feed) hidden character which is commonly mistaken with the (carriage return).
9) Since installing a CGI script is extremely difficult for new webmasters, you may want to consider asking a friend with CGI (Perl, Python, etc.) experience to walk you through the process or hire a webmaster for this part of your site.
Finally, if all else fails, you may want to consider using a PHP script! This is generally better, easier and safer.