Run a Perl or CGI script with justhost.com

For an upcoming android app I’m writing, I needed to get a perl script running on my webhost (justhost.com). For the longest time, I couldn’t get it to work. The support is definitely lacking, but I finally got it to work.

First off, their advice is to make sure that the file permissions are set to 755 for your script in your cgi-bin folder (This is done easily with the Filezilla client, right-clicking your script, and selecting “set permissions”).

Also, if you are using any installed Perl Modules, you will need to add an include path at the beginning of your script (change YOUR_USER_NAME to your host username!):

BEGIN { my $base_module_dir = (-d '/home/YOUR_USER_NAME/perl' ? '/home/YOUR_USER_NAME/perl' : ( getpwuid(

<span id="_mce_tmp">XX</span>gt;) )[7] . '/perl/'); unshift @INC, map { $base_module_dir . $_ } @INC; }

From here on out, you are on your own to figure out what’s going wrong with your script.  If it doesn’t show up when you navigate your browser to the script, all error messages go to their logs - making debugging very hard.  After contacting support, I discovered the main issue:

Premature end of script headers

After checking this site:

http://htmlfixit.com/cgi-tutes/tutorial_Common_Web_dev_error_messages_and_what_they_mean.php

I found out you need to include a print statement indicating to your browser that the output will be html. This line:

print "Content-type: text/html\n\n";

goes right after your “use” statements.

Finally, the best tip I picked up to debug your script (without asking support), is to include this line:

use CGI::Carp qw(fatalsToBrowser);

This will redirect all errors to your browser instead of the justhost log files.  Make use of this during development, but remember to comment it out in the final script (as a safety precaution - you don’t want everyone knowing your errors).

In the end you should have a working script like this:

#!/usr/bin/perl

use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/html\n\n";
print "It's finally working...";
« PREVIOUS
Fantasy football drafter GUI
NEXT »
Border Wait Android App