Discussion Locked

Running Perl In Linux 7.0

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
When I run perl in Red Hat linux 7.0 it's show the source code in the browser. What would cause it to do this? How can I change this so it will run the program and not show the program code? Please Help. Thanks.

3 replies

by Former member

it would help to know what ide or application you are trying to use, but it sounds to me like the app doesn't know that its perl and assumes its just text.

try inserting the following as your first line of code

#usr/bin/perl

nothing is allowed before it. and this assumes that you installed perl in directory
/usr/bin/perl. if not then the first line should start with a "#" followed by the path to where you have installed perl

good luck

by webmaster

The application is netscape. I agree that the app doesn't know that its perl and assumes its just text. I already have the first line of code as #/usr/bin/perl

Thank you for your help. Darryl

by shanghai sam

Firstly the best way of doing this is by using a webserver such as apache. If you are already doing this, read on! Otherwise you may need to install apache or try another aproach.

If you have Apache v1.3 or better (I tested with v1.3.22), then you can simply add 4 lines to an ".htaccess" file in that webspace to enable the perl script:

Option +ExecCGI
SetHandler cgi-script

Your perl script will have to be named something ".pl". For example "demo.pl". It will also have to have the executable bit set for the apache user ("chmod a+x" should work).

However be warned that apache does expect some extra lines from a perl script run in this way. The quickest fix for that is to add "print 'Content-Type:text/plain\n\n';" as the first output line in the script. However for more complex scripts you may want to look at the perl CGI module.

This is one of many methods you can use to enable perl script on apache, and may not work on your system. If it doesn't it may be that you do not have enough permisions to set the ExecCGI option. I think it should work on a default install, but as I have changed my configs I cannot guarantee it.

This discussion is closed to new replies.