Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Apache/CGI fcould not use Spreadsheet::ParseExcel

by PhillipHuang (Beadle)
on May 08, 2019 at 16:09 UTC ( [id://1233461]=perlquestion: print w/replies, xml ) Need Help??

PhillipHuang has asked for the wisdom of the Perl Monks concerning the following question:

I have already installed Spreadsheet::ParseExcel and Spreadsheet::WriterExcel by CPAN. When I run the perl script in command line, it runs well and return as expected. However, As run as CGI script(result.pl) by Web browser, the error messages shows

[cgi:error] [pid 4778] [client 192.168.1.104:52082] AH01215: Can't loc +ate Spreadsheet/ParseExcel.pm in @INC (@INC contains: /usr/local/lib6 +4/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/shar +e/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /var/www/ +cgi-bin/result.pl line 11.

I am sure the Spread modules are installed, and find them as the below directory:

[root@localhost ~]# find / -name 'Parser.pm' /usr/share/perl5/vendor_perl/TAP/Parser.pm /home/phillip/.cpan/build/HTML-Parser-3.72-Vmh_1r/Parser.pm /home/phillip/.cpan/build/HTML-Parser-3.72-Vmh_1r/blib/lib/HTML/Parser +.pm /home/phillip/perl5/lib/perl5/x86_64-linux-thread-multi/HTML/Parser.pm

As googled items, I try to add the path to @INC by

#result.pl use lib qw(/home/phillip/perl5/lib/perl5); use Spreadsheet:ParseExcel;
the http error_log still shows
"[cgi:error] [pid 1055] [client 192.168.1.104:56670] AH01215: Can't lo +cate Spreadsheet/ParseExcel.pm in @INC (@INC contains: /home/phillip/ +perl5/lib/perl5 /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/li +b64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 / +usr/share/perl5 .) at /var/www/cgi-bin/result.pl line 10., referer: h +ttp://192.168.1.143/ [Thu May 09 00:02:21.333414 2019] [cgi:error] [pid 1055] [client 192.1 +68.1.104:56670] AH01215: BEGIN failed--compilation aborted at /var/ww +w/cgi-bin/result.pl line 10., referer: http://192.168.1.143/"

Why run well in command line by root, and why failed by web browser? I guess perhaps it is caused by privileges, apache user can not invisit the part which owner is root. Would you please give any hint? How to resolve this? Thanks in advanced,

PH

2019-05-09 Athanasius fixed code tags

Replies are listed 'Best First'.
Re: Apache/CGI fcould not use Spreadsheet::ParseExcel
by poj (Abbot) on May 08, 2019 at 18:05 UTC
    find / -name 'Parser.pm'

    Not sure why you searched for Parser but try

    find / -name 'ParseExcel.pm'

    poj
Re: Apache/CGI fcould not use Spreadsheet::ParseExcel
by LanX (Saint) on May 08, 2019 at 16:43 UTC
    >  I guess perhaps it is caused by privileges, apache user can not invisit the part which owner is root. 

    If that's the case ...

    What are the acccess rights of the directories and files in /home/phillip/perl5/lib/perl5 ?

    IIRC files must be readable o+r , directories read and executable o+rx

    See man chmod for details.

    update

    On another note: you should consider using a clean installation and not mixing system and private installations.

    And please fix the missing code tag in your post

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      IIRC files must be readable o+r, directories read and executable o+rx

      r is not strictly required for directories, missing read permissions on a directory only prevent you from listing the directory (ls and opendir will fail). To access items in a directory, you only need "cross" (executable) permissions on the directory, and sufficient permissions on the directory items.

      For shared libraries (*.so), it actually depends on the OS implementation. Some Unix systems require them to be executable, for others, read permissions are sufficient. On Linux, you can have both variants, depending on the distribution.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        So is Perl accessing modules without checking the surrounding directory?

        Probably...

        At least in the case of perldoc - which is not relevant here - r would be needed on directories.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: Apache/CGI fcould not use Spreadsheet::ParseExcel
by pryrt (Abbot) on May 08, 2019 at 17:55 UTC

    as the anonymous monk said, things need to be set up so that the cgi script can see your locally-installed libraries. I know that in my cPanel-based webhost-provider, I have to use cPanelUserConfig; or use a different shebang line, in order for it to know to look in the modules I've installed through cPanel. (see your own webhost-provider's documentation, because your version of cPanel may be different, or you may not be using a cPanel-based system)

Re: Apache/CGI fcould not use Spreadsheet::ParseExcel
by Anonymous Monk on May 08, 2019 at 17:39 UTC

    Are you in fact using the same Perl executable for both command line and CGI? If not, that would explain your problems. The @INC looks like a system Perl, which would not normally look for modules in your personal directory.

    If you are using the system Perl, you should use the system's package manager to install modules. Using the cpan client (or its variants) can cause considerable grief, as I have learned from sad experience, and as you may be learning now. If there is no package for this module, you should probably custom-build your own Perl, and that's not a bad idea anyway, as the previous responder pointed out.

    If you are using a custom-built Perl, did you install it in a system-wide directory and then take the local::lib installer option when you initialized CPAN? You want the sudo option in this case.

      Resolved: install the Spreadsheet::ParserExcel and Spreadsheet::WriterExcel manually.

      "Using the cpan client (or its variants) can cause considerable grief, as I have learned from sad experience, and as you may be learning now. " I have learned just now, :-)

      Thank for all your kindly help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1233461]
Approved by LanX
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-12-10 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (56 votes). Check out past polls.