Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

configuring mod_perl on Apache2.4 (conf & virtual host help)?

by knox (Sexton)
on Jan 20, 2020 at 05:20 UTC ( #11111624=perlquestion: print w/replies, xml ) Need Help??

knox has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need help configure my Apache with mod_perl.

I have just installed mod_perl on via sudo apt-get install -y libapache2-mod-perl2 on Ubuntu 18. I am having a hard time figuring out what the next steps our to test perl script. I am looking at https://perl.apache.org/docs/2.0/user/handlers/http.html and trying to understand what would go in my virtual hosts file and what else I need to configure to get perl script working for Apach24 setup.

I've tried a few virtual host directives such as the one found here (with my own settings), but with no luck: https://wiki.archlinux.org/index.php/Apache_HTTP_Server/mod_perl

<VirtualHost perlwebtest:80> Servername perlwebtest DocumentRoot /srv/http/perlwebtest ErrorLog /var/log/httpd/perlwebtest-error.log CustomLog /var/log/httpd/perlwebtest-access.log combined <Directory /srv/http/perlwebtest> AddHandler perl-script .pl PerlResponseHandler ModPerl::Registry Options +ExecCGI PerlOptions +ParseHeaders AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>

Currently, its not rending any of Perl Script. I feel like I've missed an obvious step. Any ideas of what I should try next?

.

Replies are listed 'Best First'.
Re: configuring mod_perl on Apache2.4 (conf & virtual host help)?
by kcott (Archbishop) on Jan 20, 2020 at 07:44 UTC

    G'day knox,

    Welcome to the Monastery.

    It's a very long time (15-20 years) since I had to do anything with Apache virtual hosts. Any knowledge that I might have retained may well be very out-of-date. I won't attempt to provide an answer; however, the following may be of some help.

    Have a look at these documents (and follow links therein):

    The httpd.conf file itself provides a lot of hints; although, as it says,

    # Do NOT simply read the instructions in here without understanding # what they do. They're here only as hints or reminders. If you are +unsure # consult the online docs. You have been warned.

    Check the output in both the access and error logs. They may contain information that will allow you to resolve your problem. If they contain something you don't understand, post it here: "its not rending any of Perl Script" is not a particularly useful error report for us.

    Check changes to configuration as appropriate for your platform. For me, using Cygwin, that's /usr/sbin/apachectl configtest; it's quite likely you'll need something different on Ubuntu. Also bounce (stop and restart) Apache after config changes.

    You'll probably find it useful to set up aliases for your most common operations. Here's a few of mine; again, Ubuntu may be different.

    alias apache_test='/usr/sbin/apachectl configtest' alias apache_down='/usr/sbin/apachectl stop' alias apache_up='/usr/sbin/apachectl start' alias apache_ps='ps -ef | grep http'

    — Ken

      cheers Ken,

      I had to get re-aquainted with virtual hosts, so your suggestion was really helpful in eventually finding my mistake. I am on my laptop using this as a local test and completely forgot set up /etc/hosts file.

      I was just accessing everything via the full local url, eg http://127.0.0.1/projectsite/public_html/test.pl. I set up a virtual hosts with a proper server name locally ( eg projectsite.local ) then added this to my hosts file, it was all honky-dory. Part of my confusion was the assumption that mod_perl and mod_php work the same way - php works without having to set up a virtual host this way. But I found digging into virtual hosts a useful learning experience.

      thanks for your feedback, I lead me to the solution!

Re: configuring mod_perl on Apache2.4 (conf & virtual host help)?
by 1nickt (Canon) on Jan 20, 2020 at 15:34 UTC

    Hi, as stated above the Apache2 + mod_perl approach to serving web content generated by your Perl script is *very* outdated. If you are setting up a server in a new environment, or a new app in an existing server environment, I'd recommend against that framework unless there is some specific reason why it must be used.

    I used Apache + mod_perl for years, but haven't used it for more years. For a simple, intuitive, modern Perlish approach I'd recommend setting up a lightweight Perl Dancer app. Here is the Dancer2 deployment guide including instructions for running under Apache if that's your production web server. Try it; you'll be serving requests with your code before you figure out that VHost mod_perl config :-)

    Hope this helps!


    The way forward always starts with a minimal test.

      Very helpful! It became apparent trying to find solutions for getting mod_perl installed it seemed outdated. I was aware of Dancer, Mojolicious, as well as Plack. I just had a fairly simple script, so I thought that a framework might be overkill for the size of this project. I will check out Dancer, I've only read good things about it, so thanks for the recommendation!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11111624]
Approved by marto
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2023-09-29 00:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?