首页 > 解决方案 > 启动 lig​​httpd 时 perl @INC 未完成

问题描述

我正在尝试在我的 iMac(Catalina 10.15.6)上运行 TrinotateWeb(v3.2.1)。它使用轻量级浏览器 lighttpd (v1.4.55),它是我随 Homebrew 安装的。

启动服务器时,它抱怨在@INC 中找不到 HTML/Template.pm:

Can't locate HTML/Template.pm in @INC (you may need to install the HTML::Template module) 
(@INC contains: 
/Library/Perl/5.18/darwin-thread-multi-2level 
/Library/Perl/5.18 
/Network/Library/Perl/5.18/darwin-thread-multi-2level 
/Network/Library/Perl/5.18 
/Library/Perl/Updates/5.18.4 
/System/Library/Perl/5.18/darwin-thread-multi-2level 
/System/Library/Perl/5.18 
/System/Library/Perl/Extras/5.18/darwin-thread-multi-2level 
/System/Library/Perl/Extras/5.18 
.) at /Applications/Trinotate-v3.2.1/TrinotateWeb/cgi-bin/index.cgi line 15.
BEGIN failed--compilation aborted at 
/Applications/Trinotate-v3.2.1/TrinotateWeb/cgi-bin/index.cgi line 15.

但是,HTML/Template.pm 很好地安装在文件夹中/Users/simon/perl5/lib/perl5。它是使用cpan HTML::Template.

问题似乎源于@INC。

我的 .zshrc 配置文件使用 PERL5LIB 引用上述位置:

PATH="/Users/simon/perl5/bin${PATH:+:${PATH}}"; export PATH;
PERL5LIB="/Users/simon/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5L$
PERL_LOCAL_LIB_ROOT="/Users/simon/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB$
PERL_MB_OPT="--install_base \"/Users/simon/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/Users/simon/perl5"; export PERL_MM_OPT;

在终端中,@INC 包含 PERL5LIB 并因此链接 HTML/Template.pm:

➜  ~ perl -V
Summary of my perl5 (revision 5 version 18 subversion 4) configuration:
   
  Platform:
    osname=darwin, osvers=19.0, archname=darwin-thread-multi-2level
    uname='darwin osx397.sd.apple.com 19.0 darwin kernel version 18.0.0: tue jul 9 11:12:08 pdt 2019; root:xnu-4903.201.2.100.7~1release_x86_64 x86_64 '
    config_args='-ds -e -Dprefix=/usr -Dccflags=-g  -pipe  -Dldflags= -Dman3ext=3pm -Duseithreads -Duseshrplib -Dinc_version_list=none -Dcc=cc'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags =' -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -fstack-protector',
    optimize='-Os',
    cppflags='-g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -fstack-protector'
    ccversion='', gccversion='4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc-selector-opts)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector'
    libpth=/usr/lib /usr/local/lib
    libs= 
    perllibs=
    libc=, so=dylib, useshrplib=true, libperl=libperl.dylib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -fstack-protector'


Characteristics of this binary (from libperl): 
  Compile-time options: HAS_TIMES MULTIPLICITY PERLIO_LAYERS
                        PERL_DONT_CREATE_GVSV
                        PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
                        PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
                        PERL_PRESERVE_IVUV PERL_SAWAMPERSAND USE_64_BIT_ALL
                        USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
                        USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE
                        USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
                        USE_REENTRANT_API
  Locally applied patches:
    /Library/Perl/Updates/<version> comes before system perl directories
    installprivlib and installarchlib points to the Updates directory
  Built under darwin
  Compiled at Jun  5 2020 17:34:07
  %ENV:
    PERL5LIB="/Users/simon/perl5/lib/perl5"
    PERL_LOCAL_LIB_ROOT="/Users/simon/perl5"
    PERL_MB_OPT="--install_base "/Users/simon/perl5""
    PERL_MM_OPT="INSTALL_BASE=/Users/simon/perl5"
  @INC:
    /Users/simon/perl5/lib/perl5/5.18.4/darwin-thread-multi-2level
    /Users/simon/perl5/lib/perl5/5.18.4
    /Users/simon/perl5/lib/perl5/darwin-thread-multi-2level
    /Users/simon/perl5/lib/perl5
    /Library/Perl/5.18/darwin-thread-multi-2level
    /Library/Perl/5.18
    /Network/Library/Perl/5.18/darwin-thread-multi-2level
    /Network/Library/Perl/5.18
    /Library/Perl/Updates/5.18.4
    /System/Library/Perl/5.18/darwin-thread-multi-2level
    /System/Library/Perl/5.18
    /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level
    /System/Library/Perl/Extras/5.18
    .

我不明白为什么在执行 lighttpd 时@INC 没有列出所有路径作为我上面显示的实际环境?

标签: macosperllighttpd

解决方案


lighttpd exec 直接是你的 CGI(或 FastCGI),所以如果你的脚本是 xxxxx.pl 并且 contains #!/usr/bin/perl,那就是执行的。(更明确地说,不执行 zsh 并且不读取 .zshrc ,正如其他人在评论中所说的那样)

您可以将这些脚本中的第一行更新为 include #!/usr/bin/perl -I...,或者您可以修改 lighttpd.conf 以指定:

setenv.add-environment = ("PERL5LIB" => "...")

https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModSetEnv

您也可以指示 mod_cgi 执行 zsh shell 脚本来执行 perl,但这样做会更慢且效率更低。

cgi.assign = (".pl" => "/home/simon/bin/zsh-bounce-perl")

https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModSetEnv

并让zsh-bounce-perl脚本包含类似

#!/usr/bin/zsh
exec perl "$@"

推荐阅读