Search code examples
apacheperlcgiperlbrew

How can I serve CGI scripts using perlbrew w/ Apache?


Error log:

[Tue Jun 17 12:08:35 2014] [error] [client 172.18.40.199] Perl v5.16.0 required--this is only v5.10.1, stopped at index.cgi line 2.
[Tue Jun 17 12:08:35 2014] [error] [client 172.18.40.199] BEGIN failed--compilation aborted at index.cgi line 2.
[Tue Jun 17 12:08:35 2014] [error] [client 172.18.40.199] Premature end of script headers: index.cgi

This is run as the user: 'support' and support runs perlbrew w/ switch set to 5.16.3 as shown below:

# su - support
print() on closed filehandle $fh at /loader/0x1cb94a8/App/perlbrew.pm line 19.
-bash-4.1$ perl -v

This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux

What do I need to do to ensure Apache executes index.cgi w/ the perl installed by perlbrew?


Solution

  • The OS executes the interpreter identified by the shebang (#!) line of the script it was asked to execute (index.cgi). It's just a question of specifying the path to the interpreter you installed using perlbrew there.

    Execute which perl (more familiar) or perl -E'say $^X' (more reliable?) to determine the value needed.


    Let's do an example.

    One on of my machines, I get the following when using my threaded build of 5.18.2. (You'll get something different.)

    $ which perl
    /home/ikegami/usr/perlbrew/perls/5.18.2t/bin/perl
    
    $ perl -E'say $^X'
    /home/ikegami/usr/perlbrew/perls/5.18.2t/bin/perl
    

    So I'd use the following as the first line of index.cgi:

    #!/home/ikegami/usr/perlbrew/perls/5.18.2t/bin/perl