Click to See Complete Forum and Search --> : Perl installation on Apache


squishy
08-03-2006, 05:09 AM
I host my own site already using Apache. I just installed Perl. Its installed correctly, as far as I know. I ran it in the DOS prompt already and worked a script that way.

But my instructions never told me how to tweak the Apache config file to recognize it.

Primary Question: Does anyone know how to set up Apache to use Perl?

Other minutiae...
1. can I run Perl scripts anywhere on my computer? Or does it have to be over the web server/browser?

2. do my perl scripts have to be in the cgi-bin? or can they be anywhere on the server?

3. Technical distinction. What is the difference between CGI and Perl?

Sorry for bothering all of you with "easy" stuff. I try not to ask question on here unless I need to. Granted, I havent been working that long at trying to solve this, but I have been working hard. I have looked on search engines for the past three hours, straight, and all web sites I have found are either too technical, too vague, doesnt work, or simply dont get to what I need.

PineSolPirate
08-04-2006, 01:31 PM
Hi squishy, hope I can help.

As far as getting perl going in apache it kinda depends on the version of apache.
I'm going to guess Apache 1.34 or so. It doesn't matter much until you hit apache 2.

Before I get into it, you might like to take a look at mod_perl (http://perl.apache.org/) which may or may not be an easier way to get this going, but it'll perform faster (since I'm sure you run enormous data-crunching web-apps ;))

Continuing....you need to pop open httpd.conf.
Scan through or search and there should be a line that has this commented out.
AddHandler cgi-script .cgi
Uncomment it. Add " .pl" if you want scripts with the extension .pl to run too.
Now find this bunch...
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>and make it look like this...
<Directory />
Options FollowSymLinks +ExecCGI
AllowOverride None
</Directory>
Now, restart apache ("apachectl -K restart" I think...) and you should be good to go.
Also, you'll need to change all your scripts shebang lines to the correct path...
#!c:/program files/perl/bin/perl.exe
That isn't necessarily correct, just find perl.exe and put the full path there.

Now, the rest of them.
1. You can't run them from the web anywhere but in the web dir's.
2. They can be anywhere using the above config.
3. CGI is common gateway interface, it's just an acronym for a method of doing things. Perl however, is a language. You can write CGI scripts in lots of languages, Perl, Python, Shellscript, even C++

Hope that helps and is concise enough :)

squishy
08-04-2006, 05:59 PM
Thanks for the response. Appreciate it.

You did answer my final questions, thanks... but can PHP also run as a CGI? You didnt include it in your list, even though PHP is fairly popular.

I was wondering what a shebang line was... lol

As for the real issue... I am still having trouble getting my Perl to run. I keep getting a "500 Internal Server Error" on my browser.

Ok, I guess system information would be helpful.
I am running Apache 2.0.55, actually, and on Windows XP.
This Perl installation is ActivePerl 5.8.8.817.
and my shebang line is:
#!C:/Program Files/Web Hosting/Interpreters/Perl/bin/perl.exe

That extra code you had me add, "+ExecCGI", I already added that in a different <Directory> comment from prior help that I got. But I changed it as per your recommendation. I already had the AddHandler line, as well. Doesnt seem to help, though.

Also, it might be pertinent, but I am attempting to run my "test.pl" file from the web browser directly out of my cgi-bin. In other words, and I dont know that it matters, but my URL contains "cgi-bin/test.pl" I know that the cgi-bin is an alias with limited browser access.

What am I doing wrong?

squishy
08-05-2006, 12:35 AM
Thanks everyone... but I figured it out... by accident, no less. Non of the sources I looked at were right. Even the example scripts given to me as part of the installation never ran. But, I copy-pasted a script from online... it ran perfectly in my browser... off my server. So I backward engineered it!! I removed all code that I knew what it did, line by line, until I was left with little bit of code. Trial and error, I figured out what I was missing that was so mandatory. I added that line to my other scripts... and voila!!! Im sure you all know it already though... its the line that says
print "Content-type: text/html\n\n";

PineSolPirate
08-07-2006, 11:24 AM
Ouch, beaten by header code :) Congrats on finding that.
If you really want to get into perl as ytour CGI language, I recommend the CGI module from CPAN. (http://search.cpan.org/dist/CGI.pm/CGI.pm)
It's actually probably already installed. Anyway, it can make life easier and your code shorter. Look it up if you have time.