Perl Primer II: Basic CGI Scripts Troubleshooting

Simple scripts are simple to configure but sometimes things do go wrong. Here are some basic tips for painlessly dealing with perl problems

Last month, we took a look at the few basic bits of information and procedures you’ll need in order to configure and install most simple CGI scripts on a Unix server (“Perl Primer: A CGI Tutorial“).

Now, before you dive nose first into the wonderful world of interactivity, I feel I ought to just mention that sometimes these scripts can be a little touchy. Things can go wrong, so that when you get the script uploaded and try to access it, it don’t work. So, this month, we’ll go over a bit of very basic troubleshooting tips.

Again, I caution you not to be nervous. Because they can be touchy little scripts and nowhere near as forgiving as hypertext markup language (HTML), they can refuse to work because of some pretty minor errors. But those errors are easy to fix and in the end, the effort will be worth it. Assuming that the rest of your site design is crisp, clean and clear, the features you can offer your site visitors with these scripts can lift your business images into the heights of professionalism just as fast as you can get those “Hosted by Whatsit” graphics off your pages.

That said, if you are having trouble with a recalcitrant script, here are a few basic things to look for.

Did you upload the script correctly?

Yes, this seems like a pretty brainless question, but it’s valid. Check to make sure the entire script uploaded. Sometimes they get cut off during transfer, especially the larger scripts and especially if you are on a dial-up connection so that uploading is a slower process.

ASCII or binary: check before you upload

While you’re at it, double-check to make sure that you uploaded the file in ASCII rather than binary mode. Remember, uploading in binary is for graphic images like .gif, .jpg and .pdf files. For text files — and perl scripts fall under this category — you need ASCII. If you are using WS FTP-Pro, you need to be alert to this during all your uploads because the program’s default setting is binary.

Are all your system path configurations correct?

If you’re getting those pesky 500 errors, you’ll need to check to make sure that you provided the correct system path information to the program, starting with the path to perl. As a matter of fact, errors in the path to perl line are among the most common problems people have getting their scripts to work. If you have to, go back to your web host’s control panel and look this up again but make sure you have it right.

Once you’re certain that you’re script will be able to find your server perl compilor, go back and make sure that you have the rest of the system path information correctly configured. Remember that system paths always start with a slash (“/”). If you are pointing the program to a certain directory, you will usually include a trailing slash but, if you are specifically told not to include that trailing slash then you should certainly follow directions.

These are system paths, too. Make sure you didn’t inadvertently input URLs into your configuration settings when the instructions call for system paths. For that matter, also make sure you do provide URLs and not system paths when the script asks for URLs — which they sometimes do. Follow directions.

And do be sure, when you are inputting those system paths, that you are not giving your script bad directions. Correct format for system paths aren’t going to get your script running if you tell it to go looking for a directory in your cgi-bin that you the forget to create! Make sure that everything you need to put into your directory structure for the script to use is actually there. Create the directories the script needs and upload the files the script needs to find in those directories. Then give good path directions to help the script find the files it needs to complete its tasks.

Are your permissions set correctly?

This is one of those incredibly simple things that is so easy to fix that it almost seems like getting the stubborn script to finally work was nothing short of magic.

It’s also something that is fairly easy to forget to do. If you do your own webmastering, then the task of editing and uploading files is no doubt pretty routine. In fact, if that is the case, you may already be in the habit of checking to make sure you upload text files in ASCII and so are unlikely to make that particular novice mistake.

On the other hand, setting file permissions on your Unix server is not a chore that you perform regularly as you upload you files and because of that, you might forget to do it. If you don’t remember, just go back and do it again. Make sure that you set file permissions as instructed on directories as well as individual files. Particularly when it comes to subdirectories in your cgi-bin, because these files cannot ordinarily be accessed by anybody. So you have to arrange the directory so that the web page that calls the script is permitted access to that script. Don’t forget to set those permissions!

Most of the time, with the simpler scripts, these troubleshooting tips will yield results. If you are still having trouble, you can either scream for help from your web site hosting tech support people or return to the source. If you have paid for your script, you are entitled to a certain amount of customer service and even if you are working with a freebie, most sites that give away code have message boards where you can bring your perl issues and get helpful hints from the script’s author and from other webmasters.

Copyright © 2003 by Dawn Rivers Baker The MicroEnterprise Monthly. All rights reserved. Reprinted with permission.

View all contributions by

Search Engine Veteran - Enterprise SEO & Small Business Entrepreneurs. Advisor to startups for pre-launch optimization SEO Audits & consulting.