How do I use perlbrew to manage perl installations aimed at web applications?
Asked Answered
F

2

16

I have been using perlbrew to manage multiple versions of perl on a Linux Fedora notebook. I have used it with great benefit to run command-line scripts mostly using App::cmd.

I now want to move to running web applications written using CGI::Application using different perls installed in my $HOME. I am familiar with running Perl web applications in $HOMEs using Apache's user_dir or creating Virtual Hosts but I am unable to come up with a clean way of integrating this and the perlbrew managed perls. Specifically I need help in understanding and finding answers to these questions:

  1. How do install mod_perl under perlbrew?
  2. Assuming this is done, how do I configure my VirtualHost so that it picks up the correct perl that is current?
  3. If this is not possible, (which I doubt) can I at least use local installations to run vanilla CGI?

Thank you for your attention.

Frigging answered 25/9, 2010 at 18:10 Comment(0)
G
17

I don't think this is a good use for perlbrew, which moves around symlinks under its own directory. The trick is switching the mod_perl module around. Remember, mod_perl is going to be binary-incompatible between major versions of perl, and that you will have to compile it against apache for each version of perl (and apache) you want to use.

perlbrew really does two big things for you:

  • Installs perl, which is trivially easy to do on your own.
  • Switches around symlinks so perl is whatever version you want.

If you give up on that last one, perlbrew isn't really doing that much for you. I don't think the symlink feature is particularly valuable.

I think perlbrew is fine for what it is, but when you start doing things outside of its limited scope, it's time to not use it. It's supposed to be a tool to save you some time and headache, so if it's not accomplishing that goal, it's not the right tool for your situation.

In this situation, where I'm supporting a single, big web application, I give it its own perl installation that I don't let anything else use.

For your other questions:

  1. markdown placeholder

  2. You shouldn't have to configure any VirtualHost stuff. If you are using mod_perl, perl is already in there and you don't get to choose a perl. If you're using CGI stuff, you specify the perl on the shebang line. You will have to ensure apache picks up the right library directories, but I think perlbrew handles that. You might have to use SetEnv or something similar in your httpd.conf.

  3. For vanilla CGI, just point to the right (symlink) path for whatever the default perlbrew version is. The CGI program will just use whatever perl that path points to.

Gangplank answered 25/9, 2010 at 20:11 Comment(1)
> I give it its own perl installation that I don't let anything else use. Ok. But we can do such thing with help of perlbrew perlbrew install perl-5.36.1 --notest -Duseithreads -Duseshrplib -j 4 --as perl-5.36.1-apache. Voila, and we have own installation for Apache2. To my mind, it would be more complex to configure and run its own version of Apache2 for each different perl.Warrantor
H
10

See brian d foy's answer for why not to expect to use perlbrew to switch between versions of mod_perl. I also expect that you will need to run multiple Apache servers, if you need multiple different Perl versions under mod_perl.

However, using perlbrew as an easy way to build Perl is IMHO a valid thing to do, and there are few instructions available for how to run mod_perl under perlbrew.

First ensure perl is built with shared library support, by passing the -Duseshrplib flag (otherwise on 64-bit systems you will get a confusing build failure about -fPIC):

perlbrew install perl-5.16.3 -Duseshrplib

Install the development Apache libraries for your system. On Debian, this differs depending on the Apache MPM that you are using. For the prefork MPM:

sudo apt-get install apache2-prefork-dev

Or for the worker MPM:

sudo apt-get install apache2-threaded-dev

Then you need some options to build and install mod_perl2 into the right place. Note that this means cpanm will fail to build it, but you could use it to get hold of the source:

cpanm mod_perl2  # fails
cd ~/.cpanm/latest-build/mod_perl-2.0.8/   # adjust mod_perl version

Adjust the version of Perl below accordingly. (The MP_APXS option is to give the right path for Debian-based systems, which you might not need.)

perl Makefile.PL MP_APXS=/usr/bin/apxs2 \
                 MP_AP_DESTDIR=$HOME/perl5/perlbrew/perls/perl-5.16.3/
make
make install

Finally, change the LoadModule line in your Apache configuration file (adjusting paths accordingly):

LoadModule perl_module <your homedir>/perl5/perlbrew/perls/<your perl>/usr/lib/apache2/modules/mod_perl.so

Your mod_perl installation will now be running the version of Perl that you want. Install all your required CPAN modules and get going.

Hagridden answered 31/5, 2013 at 15:45 Comment(1)
This seems to be the one and only solution to manage different Perl and mod_perl versions using perlbrow within Apache. Beware... if your Apache instance is running as different user then you need to make the local Perl installation accessible for this user. I did this in my test installation with "chmod 777 -R ./" from the home directory of the user where perlbrew was installed.Deep

© 2022 - 2024 — McMap. All rights reserved.