HOW TO: Debug CGI Script Problems?

You can debug Perl CGI Scripts with the following list of things to check for first in your CGI Scripts:

Is your first line correct?

The first line of your script must tell the Web Server where to look for the Perl Interpretter. On most servers it should be:


If that doesn't work on your server, run this command in a Telnet or SSH Session:

which perl

This command should show you where perl is installed on your server. Use that location in your first line instead. For example:


Also, make sure that this appears on the very first line. There can be NO spaces between the top of the perl script and this line. If there are, then it won't work.

» Does your CGI Script have the right permissions?

Perl CGI scripts should have limited permissions. In most cases, Perl scripts should be owned by your user account, and have permissions of 755. If your web server is setup with strict permissions, scripts that do not have a permission setting of 755 will not be run. Instead a "Premature end of script headers" error will occur. If you are getting these errors, this is the first thing you should check.

To check to see if your perl script has the correct permissions, run this command:

ls -l perlscript.cgi

(Use the name of your script instead of perlscript.cgi though.) You should see something similar to the following:

-rwxr-xr-x    1 aiv      aiv        173231 Jan 19 21:04 files.cgi*

The below string shows permissions of 755, that the script is owned by aiv and shared with the group aiv. When you run the ls -l command, you should see something similar. If you don't, run the following command to correct the permissions:

chmod 755 perlscript.cgi

(Use the name of your script instead of perlscript.cgi though.) This will set the script's permissions to the correct setting.

» Did you upload in ASCII mode?

If you used FTP to put your Perl script on the server, make sure that you used the ASCII transfer mode. You will get errors running your script if you uploaded it using BIN mode. Often times these errors make no sense. If this sounds like what is happening to you, upload the script again, and make sure you do it in ASCII mode. This may be the fix for your problem.

» Did you check for syntax errors?

From a telnet or ssh shell session, run the following command on your script:

perl -c scriptname.cgi

(Note: Substitute your script's name for "scriptname.cgi")

If you see any error messages when you run this command, you will need to fix these errors before the script will run correctly.

» Does the CGI Script run in a shell session?

From a telnet or ssh shell session, run the following command on your script:

perl scriptname.cgi

(Note: Substitute your script's name for "scriptname.cgi")

The script should run without error. It may even print out HTML to the shell session. This is good, it means that your script appears to work in at least a basic form.

If on the other hand you get error messages when you run the script like this - then you need to fix these errors before the script will work.

The web server will run a similar command when you try to use the script in your browser. If it doesn't work on the shell - it isn't going to work with your browser either.

» Did you look in the logs?

If all else fails - look in the web server logs. On most Apache web servers (like the ones we use), the error logs will be here:


(If you cannot find the error log on the server you use, ask the system administrator where it is.)

Once you know where the log file is, you want to be able to see new errors as they are added to the log. This way you can access your script via your web browser, and see what error it produces in the log.

To do this, open a telnet or ssh and run the following command:

tail -f /usr/local/apache/logs/error_log

This will produce a running display of the latest errors to appear in the error log. Now that you have this ready, access your script in your browser. Then immediately switch back to your telnet or ssh session. You should see an error message in the logs. Copy and paste this error message to somewhere you can keep it handy. (If you don't do this, it may scroll off the screen - sometimes the error log fills up with new messages fast - and it can move your messages off the screen.)

Now examine the error message you copied and see if you can use it to fix your script. Chances are, it will give you a very good idea of how to fix the problem.


  • Email, SSL
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

What is the difference between shared SSL and private SSL?

A shared SSL displays as https://ip/~yourusername/. A private SSL would display as...

Why are my FrontPage extensions not working?

You must first make sure you have installed the extensions from going into your cpanel and...

Application Paths

Here are the applications paths. If you do not see what you are looking for, please email...

Custom error pages

To create a custom error page for your account you will need to upload a file with the...

How do I use SSL to setup my email?

Set your mail server to the host name for SMTP/POP3/IMAP (instead of and then make...