简体   繁体   中英

How to specify Perl version for apache2 mod_cgi?

I have installed additional versions of Perl on a Fedora 21 system. On the PATH, my custom Perl (5.10.0) has priority over the distro's default 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:

5.018004

How can you direct Apache to use a specific version of Perl?

When using plain CGIs, the OS (through the #! line) is responsible for picking the interpreter. As we have established, the shebang was pointing to the wrong version of the interpreter.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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