简体   繁体   English

如何使用带有Apache的perlbrew提供CGI脚本?

[英]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: 它以用户身份运行:“ support”,并且支持运行perlbrew w /将开关设置为5.16.3,如下所示:

# 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? 为了确保Apache执行由perlbrew安装的perl的index.cgi,我需要做什么?

The OS executes the interpreter identified by the shebang ( #! ) line of the script it was asked to execute ( index.cgi ). 操作系统将执行由要求执行的脚本的shebang( #! )行标识的解释器( index.cgi )。 It's just a question of specifying the path to the interpreter you installed using perlbrew there. 这只是指定使用perlbrew在此处安装的解释器的路径的问题。

Execute which perl (more familiar) or perl -E'say $^X' (more reliable?) to determine the value needed. 执行which perl (更熟悉)或perl -E'say $^X' (更可靠?)以确定所需的值。


Let's do an example. 让我们做一个例子。

One on of my machines, I get the following when using my threaded build of 5.18.2. 在我的一台机器上,使用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 : 所以我将以下内容用作index.cgi的第一行:

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

use a proper perl/bash shebang.. 使用适当的perl / bash shebang。

the following would work perfectly 以下将完美地工作

#!/bin/bash
export PERLBREW_ROOT=/opt/perlbrew
export PERLBREW_HOME=/tmp/.perlbrew
export SHELL=/bin/bash #not really needed
unset XTERM_SHELL #not really needed
source ${PERLBREW_ROOT}/etc/bashrc
perlbrew use perl-5.21.9 > /dev/null 2>&1 # you can add your version here... 
eval 'exec perl -x -wS $0 ${1+"$@"}' if 0;
#! -*-perl-*-
# line 10 The above line/string resets the perldebug line-numbering... 
print "The perl interpretter running this code is $^X\n" ; 
print "This is perl version $^V\n" ; 
print "Hello PerlBrew \n" ;
die "This should be line number 14\n"  ; 
print "x\n" ; 

That will result in... 这将导致...

The perl interpretter running this code is /opt/perlbrew/perls/perl-5.21.9/bin/perl5.21.9
This is perl version v5.21.9
Hello PerlBrew 
This should be line number 14

Hope this helps... 希望这可以帮助...

G G

Is there a shebang in index.cgi? index.cgi中有一个shebang吗? Which perl does it point to? 它指向哪个perl?

I believe the shebang should point to your custom perl not the system perl that you have shown. 我相信shebang应该指向您的自定义perl,而不是您已显示的系统perl。

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

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