Unable to execute Perl Scripts from Cgi-bin

NeonFlash

Registered
Aug 30, 2012
4
0
1
cPanel Access Level
Website Owner
Hi,

I am new to the forum here ) At first, I want to give a high level overview of the type of access I have to my Cpanel and Web Server.

My web sites runs on a Shared Hosting Server (service provided by byethost.com). I have access to Cpanel.

I want to execute some Perl Scripts on the Server Side. So, I placed my example.pl perl script inside the cgi-bin folder.

The permissions for the public_html and cgi-bin folder are set appropriately (0750)

Perl is installed on my Web Server most likely (since it is a Linux Web Server and moreover I am provided options in the Cpanel to download more Perl modules from CPAN).

As a test, I wrote the following script, which is seen on most of the sites already:

Code:
#! /usr/bin/perl
print "Content-type: text/html\n\n";
print "This script just executed on the Server side\n";
I save this script as example.pl inside the cgi-bin folder. The permissions of the script are set to 755.

I am quite sure that Perl is installed on the Server since when I place this script inside the cgi-bin folder, the icon of Perl appears next to the script (recognized due to the extension by Cpanel).

Now, I browse to the location where this script is saved from my Browser (Firefox) to execute this script.

Code:
http://example.com/cgi-bin/example.pl
and I get an Internal Server Error.

I checked my error_log file (downloaded from the Cpanel). It does not show any error associated with the path: "cgi-bin/example.pl"

It shows errors such as: "File not found /500.shtml" <- similar to this though not exact. 500.shtml is corresponding to the Internal Server Error page, I guess.

I have looked up this error message associated with Perl CGI on Google and it appears to be a known issue. However, even after trying various workarounds, I am unable to execute this script.

Help would be appreciated. Let me know if there is more information required to troubleshoot.

Thanks.
 

NeonFlash

Registered
Aug 30, 2012
4
0
1
cPanel Access Level
Website Owner
Hi,

Yes, this is how I got it working. The script mentioned in the first post will work. The most important reason for the 500 Internal Server Error in the case of CGI Perl Script is not setting the proper HTTP Response Header.

In our case, it would be, Content-type: text/html \n\n

It is important to note that there are 2 newline characters which have to be appended at the end.

Initially I had not done that, which was resulting in the error message.

Also, please note that the Content-type header is case sensitive.

Hope this helps someone else who might face a similar problem.