LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 04-27-2011, 12:05 PM   #1
Larry James
Member
 
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Ubuntu, Raspbian
Posts: 381

Rep: Reputation: 40
How to setup mod_perl with scripts and html files in the same directory?


I have mod_cgi working perfectly. However, it turns out there are features of mod_perl that I'm trying to use. I have followed all the documentation I can find on using Ubuntu's mod_perl install with Apache2. There seems to be some type of problems with the mod_perl's documentation, as it doesn't work as it's defined. However, I found a modification to make it work, but only is designated directories. If I tried to use in a directory with my other HTML files the regular HTML files will fail.

Using these steps (but using apt-get's install rather than compiling the tar ball). I did as follows:

( http://perl.apache.org/docs/2.0/user...tart_fast.html )

placed this in the httpd.conf file (which was basically the same as "a2enmod perl".

httpd.conf line:

Code:
LoadModule perl_module /usr/lib/apache2/modules/mod_perl.so

Alias /perl/ /home/web/perl/

  <Directory /home/web/perl>
      SetHandler perl-script
      PerlResponseHandler ModPerl::Registry
      PerlOptions +ParseHeaders
      Options +ExecCGI
      Order allow,deny
      Allow from all 
  </Directory>
Now a perl script called using the /perl/ alias will work as long as it's in the alias directory. If I add those lines that makes the /perl/ alias directory work to my root directory so that I can have my scripts integrated in the same directories as HTML files will allow .pl and .cgi files to work but the html files will fail.

What I really want to do is configure the system so that the scripts will work in the userdir area so that anyone that has his own public_html files and work on programming independently. Also, I prefer using my userdir for my programming and testing.

By the way, the docs use " <Location" rather than "<Directory" to specify the area. The location won't do anything on the system. When that's used rather than "<Directory" the *.cgi scripts will be opened in the browser as text. The *.pl files will cause the browse to prompt for downloading.

Thanks in advance for anyone having knowledge or insight on how to use mod_perl in directories that can be integrated with both scripts and html files. If I can do it from the main server, I'm sure I'll be able to do the same thing in the userdir area.

By the way, the key might be finding a way to make the "<Location" specification work. That way the area can have both a "<Location" and "<Directory" with "<Location" proving support for the *cgi and *.pl files and the "<Directory" specification proving support for the other option directives.

-- L. James

--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
 
Old 04-27-2011, 01:44 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

Well, I don't know if the following works with mod_perl, but normally in apache, if you want to run scripts in a directory other than cgi--bin, you can use "Addhandler cgi-script ...". So you could try to replace cgi-script with perl-script and see if it works:
Code:
<Directory /var/www/html>
      AddHandler perl-script .cgi .pl
---snip---
</Directory>
Regards
 
Old 04-27-2011, 04:37 PM   #3
Larry James
Member
 
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Ubuntu, Raspbian
Posts: 381

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by bathory View Post
Hi,

Well, I don't know if the following works with mod_perl, but normally in apache, if you want to run scripts in a directory other than cgi--bin, you can use "Addhandler cgi-script ...". So you could try to replace cgi-script with perl-script and see if it works:
Code:
<Directory /var/www/html>
      AddHandler perl-script .cgi .pl
---snip---
</Directory>
Regards
Thanks, Bathory. That doesn't do it. It doesn't have any effect with mod_perl. I believe the mod_perl equivalent of that is the "SetHandler perl-script" statement, which is a requirement for mod_perl to work. Removing that statement and the *.cgi will be opened up as text in a browser. A *.pl file will invoke the browser to download it.

-- L. James

--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
 
Old 04-27-2011, 05:06 PM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
You use SetHandler if you want anything in a <Directory...>, <Location...> to be treated as a script. If you want to run some files as scripts based on their extension, then you use AddHandler.
It looks like "AddHandler perl-cgi ..." is valid, but maybe you need to use different mod_perl directives (e.g. PerlHandler Apache::Registry).
Take a look at this example to see how it's done

Regards
 
Old 04-27-2011, 06:01 PM   #5
Larry James
Member
 
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Ubuntu, Raspbian
Posts: 381

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by bathory View Post
You use SetHandler if you want anything in a <Directory...>, <Location...> to be treated as a script. If you want to run some files as scripts based on their extension, then you use AddHandler.
It looks like "AddHandler perl-cgi ..." is valid, but maybe you need to use different mod_perl directives (e.g. PerlHandler Apache::Registry).
Take a look at this example to see how it's done

Regards
Thanks, Bathory. I'm still trying various combinations. So far none of them are working. The first combination I tried was to just change the directories and servername to my virtual host. This is the error that happens when restarting Apache2:

Code:
ljames@hera5:~$ sudo service apache2 restart
Syntax error on line 6 of /etc/apache2/sites-enabled/hera5.conf:
PerlModule directive not allowed in a <Directory> block
Action 'configtest' failed.
The Apache error log may have more information.
   ...fail!
ljames@hera5:~$
Those directives are imperative to use the features of mod_perl.

-- L. James

--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
 
Old 04-28-2011, 10:17 AM   #6
Larry James
Member
 
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Ubuntu, Raspbian
Posts: 381

Original Poster
Rep: Reputation: 40
I learned what the problem was with the mod_perl not working properly. The mod_cgi's AddHandler's directive ( AddHandler cgi-script .cgi .pl ) doesn't have any effect on mod_perl's option. Mod_perl requires the Files directive for it to be invoked:

Code:
<Files ~ "\.(pl|cgi)$">
    SetHandler perl-script
    PerlResponseHandler ModPerl::PerlRun
    Options +ExecCGI
    PerlSendHeader On
 </Files>
It took me forever to find this. I hope this information will spare others who might want to use the many features of mod_perl a lot of time.

-- L. James

--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
 
Old 04-28-2011, 11:48 AM   #7
widget
Senior Member
 
Registered: Oct 2008
Location: S.E. Montana
Distribution: Debian Testing, Stable, Sid and Manjaro, Mageia 3, LMDE
Posts: 2,628

Rep: Reputation: 497Reputation: 497Reputation: 497Reputation: 497Reputation: 497
This is great.

What would also be great is to mark the thread solved so that folks with this problem, doing a forum search, will find this thread and know that someone got it working.

You will find that under thread tool on the top bar of the posts under thread tools.
 
Old 04-28-2011, 11:53 AM   #8
Larry James
Member
 
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Ubuntu, Raspbian
Posts: 381

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by widget View Post
This is great.

What would also be great is to mark the thread solved so that folks with this problem, doing a forum search, will find this thread and know that someone got it working.

You will find that under thread tool on the top bar of the posts under thread tools.
Sorry Widget. Thanks for nudging me. I always do, but was a bit slow about it this time.

I'm sure I would have noticed it by the next time I had another question... which is soon. It'll take me a few hours to do some research so that I'll be sure to include all the important information with the post.

Thanks again for people like you keeping the resource productive in this manner.

-- L. James

--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Modifying HTML files in a directory casperl Programming 3 05-11-2007 03:18 PM
Automatically Copying files from the ftp directory into the html directory swatward Linux - General 3 04-17-2005 10:55 PM
apache server setup and how to place files in the var/www/html directory dramous Linux - Newbie 7 09-28-2004 04:18 AM
apache server setup and how to place files in the var/www/html directory dramous Linux - Software 3 09-25-2004 02:38 AM
apache server setup and how to place files in the var/www/html directory dramous Linux - General 2 09-25-2004 01:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 10:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration