LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Perl support does not work with apache after its installed/configured (https://www.linuxquestions.org/questions/linux-server-73/perl-support-does-not-work-with-apache-after-its-installed-configured-723032/)

exceed1 05-01-2009 05:28 PM

Perl support does not work with apache after its installed/configured
 
Hi

I have a debian 5.0 box with apache2 installed (i used "aptitude install apache2" to install apache2). After i installed apache i also installed libapache-mod-perl2 (i used "aptitude install libapache2-mod-perl2) since im going to be using apache to run perl scripts.

The LoadModule directive was added in the apache configuration as well as the "AddHandler cgi-script cgi pl". The cgi-bin/ directory is already configured with "ExecCGI" and ScriptAlias is set to "ScriptAlias /cgi-bin/ /var/www/cgi-bin".

When i run the following script:
Code:

#!/usr/bin/perl -w
print "Content-type: text/html" ;
print "test" ;

It only shows me a download dialog which i wierd since i have added the mod_perl apache module to apache. I have looked at the error log for apache and it says nothing at all.

The /var/www/cgi-bin directory is owned and readable by the user that is running apache and the perl scripts being run is executable.

I just dont know what more to do here and i would appericiate it if someone could help me out here.

forrestt 05-01-2009 05:37 PM

Try

Code:

#!/usr/bin/perl -w
print "Content-type: text/html\n";
print "test";

HTH

Forrest

exceed1 05-01-2009 05:42 PM

I tried it and im still getting the download dialog when typing in http://localhost/cgi-bin/test2.pl

Quote:

Originally Posted by forrestt (Post 3527245)
Try

Code:

#!/usr/bin/perl -w
print "Content-type: text/html\n";
print "test";

HTH

Forrest


forrestt 05-01-2009 05:45 PM

Did you stop and start apache after you made the change?

Forrest

exceed1 05-01-2009 05:47 PM

I stopped and started apache now, no change. I dont understand why i would need to restart apache just because a new script was added, i know its not necessary to do this..but, that said it didnt change anything.

forrestt 05-01-2009 06:16 PM

OK, I was just thinking that since you are using mod_perl it might be caching the script (forgetting that it would reload it if the file was modified). Anyway, it's been a while since I've done perl web stuff. Anyway, I think I was on the right track initially. But, like I said, it's been a while. You actually need two \n's at the end of your Content-type line, not just one. So, try that and let me know.

Forrest

exceed1 05-01-2009 06:31 PM

Ok, interesting.

I now ran the following script:
Code:

#!/usr/bin/perl -w

print "content-type: text/html \n\n";
print "test";

There were no changes, the download dialog still appeared.
Under the /var/cache/apache2 directory i can see that there is a directory called "mod_disk_cache", but this directory is empty.
I also cleared firefox' cache before i restarted apache and tried to run the script again. I dont know how i would clear mod_perl' cache.

forrestt 05-01-2009 06:37 PM

The space may also be causing a problem. However, it doesn't appear that your server is even trying to run the command. It looks like you are trying to serve it up as a file. You may need to revisit your config.

Forrest

exceed1 05-01-2009 06:54 PM

I tried to run it without the space now, but it didnt change anything. You seem to be correct when you say that apache doesnt even seem to be running the file as a script. The following is shown in the access log when i try to run the file:
127.0.0.1 - - [02/May/2009:01:43:21 +0200] "GET /cgi-bin/test2.pl HTTP/1.1" 200 72 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko/2008122011 Iceweasel/3.0.5 (Debian-3.0.5-1)"

I have checked the apache configuration again, but i cant see anything thats missing. It is only the "LoadModule", "AddHandler" that is needed isnt it ? I have the ExecCGI as well but i dont know if this is actually needed when using mod_perl. I have read some articles on the net and searched google, but they only seem to describe what i have done.

I also searched for the mod_perl caching problems and it looked like mod_perl only compiled the code one time, but im not sure about this, and if this is the case, then how would it be cleared or what would be needed to do to re-compile the file again.

forrestt 05-01-2009 09:22 PM

Here are the lines from my httpd.conf that I had to modify to get cgi-bin to execute scripts:

556 # ScriptAlias: This controls which directories contain server scripts.
557 # ScriptAliases are essentially the same as Aliases, except that
558 # documents in the realname directory are treated as applications and
559 # run by the server when requested rather than as documents sent to the client.
560 # The same rules about trailing "/" apply to ScriptAlias directives as to
561 # Alias.
562 #
563 ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
564
565 #
566 # "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
567 # CGI directory exists, if you have that configured.
568 #
569 <Directory "/var/www/cgi-bin">
570 AllowOverride None
571 Options ExecCGI
572 Order allow,deny
573 Allow from all
574 </Directory>

HTH

Forrest

p.s. The numbers are just line numbers.

exceed1 05-02-2009 05:50 AM

Thanks for answering forrestt. I already have this configuration present in apache, thats what makes it so wierd that it doesnt work. I cant imagine what it can be. Ill continue to search the net, and read in my apache book to try to figure out whats actually happening here. Please do reply if you have any more ideas :)

exceed1 05-02-2009 10:24 AM

I downloaded, compiled and installed Apache 2 and then added mod_perl2 through the CPAN shell. And after adding the "LoadModule" line to the apache config. the perl scripts worked. I dont have any logical explanation to why debian' specific apache configuration didnt work though.


All times are GMT -5. The time now is 01:19 PM.