How do I specify the Perl version for apache2 mod_cgi?
I have installed additional Perl versions on Fedora 21. In the PATH, my custom Perl (5.10.0) takes precedence over the 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 a version of Perl 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?
source to share
When using simple CGIs, the OS (via the #! Line) is responsible for choosing an interpreter. As we established, the shebang was pointing to the wrong interpreter version.
The easiest way is to edit it. If you need the same script to work with two different versions of perl depending on the context of the call, you can use something like #!/usr/bin/env perl
in the shebang to make it respect the environment, then change the variable PATH
for apache.
If you cannot edit the shebang there is an option to walk through mod_perl
(make sure you compile it with the correct version) if you don't mind using that particular version for the entire web server.
Another way is to start the webserver in some container (chroot, lxc, docker, or just use the mount namespaces) so that yours /usr/bin/perl
point to some other version of the interpreter.
source to share