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.
So I went through my basic debugging steps:
- Is there something wrong with the perl script?
- Are permissions set appropriately for apache to execute the perl script?
- Are they any issues with file encoding (my file is UTF-8 for international characters)?
- 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: myscript.pl
[Tue Apr 15 XX:XX:XX 20XX] [error] (2)No such file or directory: exec of ‘/var/www/cgi-bin/myscript.pl’ 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.
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.