[SOLVED] How to setup mod_perl with scripts and html files in the same directory?
UbuntuThis forum is for the discussion of Ubuntu Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
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.
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:
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:
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.
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
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.
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:
Distribution: Debian Testing, Stable, Sid and Manjaro, Mageia 3, LMDE
Posts: 2,628
Rep:
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.