如何使用 perlbrew 管理针对 Web 应用程序的 Perl 安装?
我一直在使用 perlbrew 来管理 Linux Fedora 笔记本上的多个版本的 perl。我使用它来运行命令行脚本有很大的好处,主要使用 App::cmd。
我现在想转而使用不同的 perls 来运行使用 CGI::Application 编写的 Web 应用程序安装在我的 $HOME
中。我熟悉使用 Apache 的 user_dir
在 $HOME
中运行 Perl Web 应用程序或创建虚拟主机,但我无法想出一种将其与 perlbrew 集成的干净方法托管 perls。具体来说,我需要帮助来理解和找到这些问题的答案:
- How do install mod_perl under perlbrew?
- 假设完成此操作,我如何配置我的 VirtualHost,以便它选择当前正确的 perl?
- 如果这是不可能的,(我怀疑)我至少可以使用本地安装来运行普通 CGI?
感谢您的关注。
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 $HOME
s 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:
- How do install mod_perl under perlbrew?
- Assuming this is done, how do I configure my VirtualHost so that it picks up the correct perl that is current?
- If this is not possible, (which I doubt) can I at least use local installations to run vanilla CGI?
Thank you for your attention.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这对于 perlbrew 来说不是一个很好的用途,它在自己的目录下移动符号链接。诀窍是切换 mod_perl 模块。请记住,mod_perl 在主要版本的 perl 之间是二进制不兼容的,并且您必须针对要使用的每个版本的 perl(和 apache)针对 apache 进行编译。
perlbrew 确实为您做了两件大事:
perl
是您想要的任何版本。如果你放弃了最后一项,perlbrew 并没有真正为你做那么多。我不认为符号链接功能特别有价值。
我认为 perlbrew 本身就很好,但是当你开始在它的有限范围之外做事情时,是时候不要使用它了。它应该是一个可以为您节省时间和解决麻烦的工具,因此,如果它没有实现该目标,那么它就不是适合您情况的工具。
在这种情况下,我支持单个大型 Web 应用程序,我给它自己的 perl 安装,我不让其他任何东西使用。
对于您的其他问题:
markdown 占位符
您不必配置任何
VirtualHost
内容。如果您使用 mod_perl,perl 已经在那里,您无需选择 perl。如果您使用 CGI 内容,则可以在 shebang 行指定 perl。您必须确保 apache 选择正确的库目录,但我认为 perlbrew 可以处理这个问题。您可能必须在 httpd.conf 中使用SetEnv
或类似的东西。对于普通 CGI,只需指向默认 perlbrew 版本的正确(符号链接)路径。 CGI 程序将仅使用该路径指向的任何 perl。
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:
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:
markdown placeholder
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 useSetEnv
or something similar in your httpd.conf.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.
请参阅 brian d foy 的回答,了解为什么不期望使用 perlbrew 在 mod_perl 版本之间切换。我还预计,如果您需要 mod_perl 下的多个不同 Perl 版本,您将需要运行多个 Apache 服务器。
然而,使用 perlbrew 作为构建 Perl 的简单方法,恕我直言,这是一件有效的事情,并且几乎没有关于如何在 perlbrew 下运行 mod_perl 的说明。
首先通过传递 -Duseshrplib 标志来确保 Perl 是使用共享库支持构建的(否则在 64 位系统上,您将遇到有关 -fPIC 的令人困惑的构建失败):
为您的系统安装开发 Apache 库。在 Debian 上,这取决于您使用的 Apache MPM。对于 prefork MPM:
或者对于工作 MPM:
然后您需要一些选项来构建 mod_perl2 并将其安装到正确的位置。请注意,这意味着 cpanm 将无法构建它,但您可以使用它来获取源代码:
相应地调整下面的 Perl 版本。 (MP_APXS 选项是为基于 Debian 的系统提供正确的路径,您可能不需要该路径。)
最后,更改 Apache 配置文件中的 LoadModule 行(相应地调整路径):
您的 mod_perl 安装现在将运行以下版本你想要的 Perl。安装所有必需的 CPAN 模块并开始。
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):
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:
Or for the worker MPM:
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:
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.)
Finally, change the LoadModule line in your Apache configuration file (adjusting paths accordingly):
Your mod_perl installation will now be running the version of Perl that you want. Install all your required CPAN modules and get going.