1
votes

My OS is Debian Buster. My cgi-bin is in /var. The CPAN module is HTML::Template and located in /perl5/lib/perl5/HTML as installed by cpanm. My server is Apache2 and appears to be configured correctly by all the research I have done (but something must be wrong somewhere). My browser is Firefox , but I also use curl for testing. I can run cgi perl scripts without perl modules from localhost/cgi-bin/ successfully. I can run perl scripts WITH 'use HTML::Template' from the command line with ./ with perfect HTML output BUT, AND THIS IS THE PROBLEM I cannot run these from localhost either with the browser or curl when they include a perl module such as HTML::Template.

The Apache2 error message is BEGIN failed--compilation aborted at /var/cgi-bin/templateOne.cgi line 5.: /var/cgi-bin/templateOne.cgi [Wed Oct 16 00:01:23.341309 2019] [cgi:error] [pid 3743] [client ::1:36728] End of script output before headers: templateOne.cgi

Now line 5 of the script is use HTML::Template;

So it fails to either locate or compile the module, but since the program works perfectly from the command line then Apache2 I assume is unable to locate the module.

I have tried using push(@INC, '//Perl5/lib/perl5/HTML'); at the start of the script but this does not work either.

Does any one have a suggestion

1
It is likely in your home directory, not perl5 in the root directory. File paths are also case sensitive. It also looks up based on the whole module name so the library path you are actually looking for is /home/youruser/perl5/lib/perl5.Grinnz
Do not update @INC manually, use lib or you will not get version and arch specific instllations (such as XS code).Grinnz
You can also use SetEnv to add the directory to the PERL5LIB environment variable for CGI scripts.Grinnz
BEGIN failed--compilation aborted is never the first error message; what error are you actually getting?ikegami
push(@INC, '//Perl5/lib/perl5/HTML') should be use lib '/perl5/lib/perl5'; You might be modifying @INC too late --use lib will change it at compile-time -- you misspelled perl5, and you shouldn't have included HTML.ikegami

1 Answers

1
votes

Thank you for those who provided comments. I have used the advice given by Grinnz who pointed me to the use of 'use lib /path /to /module' By using the use lib statement with the path to the Template module as the second line of the script and before the use HTML::Template statement, the script worked perfectly. Thanks again.