Select Page

I’m no perl guru. I’m wouldn’t even call myself a perl novice. A virgin perl is a rare find. Hours of debugging a simple perl script left me befuddled. I’m running an apache server and placed some simple perl scripts to return result content in the /var/www/cgi-bin dir. I could execute these scripts successfully from the command line with /var/www/cgi-bin as my working directory. However, when I did a curl, I got no output.
curl “http://myserver/cgi-bin/”

So I went through my basic debugging steps:

  1. Is there something wrong with the perl script?
  2. Are permissions set appropriately for apache to execute the perl script?
  3. Are they any issues with file encoding (my file is UTF-8 for international characters)?
  4. Is my perl script printing out the http headers prior to crapping out any errors before hand? (This could cause apache to complain about the script)

All these questions proved fruitless albeit informative. I decided to look at the apache error log:
[Tue Apr 15 XX:XX:XX 20XX] [error] Premature end of script headers:
[Tue Apr 15 XX:XX:XX 20XX] [error] (2)No such file or directory: exec of ‘/var/www/cgi-bin/’ failed.

I resorted to google and the perlmonks came to my rescue. The verdict turned out to be that apache was using a different perl path than I was.

#which perl

my script

My perl script’s first line of code was the culprit. The solution was to either create a symbolic link or to modify the perl path in my perl script. I did the latter and things are just fine now.