简体   繁体   English

如何为apache2 mod_cgi指定Perl版本?

[英]How to specify Perl version for apache2 mod_cgi?

I have installed additional versions of Perl on a Fedora 21 system. 我在Fedora 21系统上安装了其他版本的Perl。 On the PATH, my custom Perl (5.10.0) has priority over the distro's default Perl (5.18.4) 在PATH上,我的自定义Perl(5.10.0)优先于发行版的默认Perl(5.18.4)

user$ perl -v
> This is perl, v5.10.0 built for x86_64-linux

root# perl -v
> This is perl, v5.10.0 built for x86_64-linux

However, when printing the Perl version in a script served by Apache, it appears to be using the "wrong" version: 但是,在Apache提供的脚本中打印Perl版本时,它似乎使用了“错误”版本:

5.018004

How can you direct Apache to use a specific version of Perl? 如何指导Apache使用特定版本的Perl?

When using plain CGIs, the OS (through the #! line) is responsible for picking the interpreter. 使用普通CGI时,OS(通过#!行)负责选择解释器。 As we have established, the shebang was pointing to the wrong version of the interpreter. 正如我们所建立的那样,shebang指向了错误的翻译版本。

The easiest way is to edit it. 最简单的方法是编辑它。 If you need the same script to work with two different perl versions depending on the call context, you can use something like #!/usr/bin/env perl in the shebang to have it respect the environment, then change the PATH variable for apache. 如果你需要相同的脚本来处理两个不同的perl版本,具体取决于调用上下文,你可以在shebang中使用类似#!/usr/bin/env perl的东西让它尊重环境,然后为apache更改PATH变量。

If you cannot edit the shebang, there is the option of going through mod_perl (make sure you compile it against the desired version) if you don't mind using this specific version for the whole webserver. 如果你不能编辑shebang,可以选择通过mod_perl (确保你根据所需的版本编译它),如果你不介意使用这个特定版本的整个网络服务器。

Another way would be to run the webserver within some kind of container (chroot, lxc, docker, or just using mount namespaces) so that your /usr/bin/perl points to some other version of the interpreter. 另一种方法是在某种容器(chroot,lxc,docker或仅使用mount命名空间)中运行web服务器,以便你的/usr/bin/perl指向其他版本的解释器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM