Forum Moderators: coopster & phranque

Message Too Old, No Replies

“Internal Server Error” when running perl scripts

         

MrDOS

4:16 pm on Nov 21, 2022 (gmt 0)

5+ Year Member Top Contributors Of The Month



Good day!
I have an issue where I receive “Internal Server Error” when running perl scripts in the browser.
Here’s an example script that works OK when running from the Cygwin Terminal:
#!/usr/local/bin/perl
use DBI;
my @ary = DBI->available_drivers();
print @ary;

print "Content-type:text/html\n\n";
print "<html><head><title>My First Script</title></head>\n\n";
print "<body>\n";
print "<p>Hello from <b>mpl.pl</b></p>\n";
print "</body></html>";


But that same script fails in the web browser. Here's the last error in /var/log/httpd/error_log
AH01215: Can't locate loadable object for module DBI in @INC

DBI.pm is in at least 2 of the locations listed in @INC
$ ll /usr/local/lib/perl5/site_perl/5.32/x86_64-cygwin-threads/DBI.pm
-rwxr-xr-x 1 svc_dpa_sql Domain Users 318199 Nov 17 10:18 /usr/local/lib/perl5/site_perl/5.32/x86_64-cygwin-threads/DBI.pm*

I want to post httpd.conf here, but I feel it will make the post too large, so I can send later if it helps.

Where would you look next?

Thanks so much!

Brett_Tabke

5:14 pm on Nov 21, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



The print @ary; line is before the 'content-type'. Switch those two around. Content type needs to be the first thing printed.

MrDOS

5:34 pm on Nov 21, 2022 (gmt 0)

5+ Year Member Top Contributors Of The Month



Thanks! so much for the quick reply!
Unfortunately, I get the same result. (This script is just a simple test script to verify DBI is working. The actual prod code was working on my last system at another shop).

Brett_Tabke

7:25 pm on Nov 21, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Probably different perl module permission requirements. Cpanel on the box? If so, then the perl module needs to be installed from there and not command line. That said, dbi should be default installed on cpanel. hmm. I bet it is still a permissions thing.

Log in SSH as the "webserver" if you can or as the "domain" user and see if the script runs from command line.

Brett_Tabke

7:27 pm on Nov 21, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Also, do a simple script that prints a content type, and then spits out your @INC.

#!/usr/local/bin/perl
use DBI;
print "Content-type:text/html\n\n";
print qq(@INC);


then ck that in the browser to see that DBI is indeed on the path.

MrDOS

7:52 pm on Nov 21, 2022 (gmt 0)

5+ Year Member Top Contributors Of The Month



I am thinking as well that it is maybe a permissions thing. Yes, DBI.pm is in the @INC (see the original post)

I am not familiar with Cpanel -- at least I did not install it.

Your simple script also results in "Internal Server Error" when run from the browser 9and works fine from the Cygwin terminal).

phranque

10:49 pm on Nov 21, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



try this (simply to see what @INC is in the apache environment):
#!/usr/local/bin/perl
print "Content-type:text/html\n\n";
print qq(@INC);

MrDOS

11:01 pm on Nov 21, 2022 (gmt 0)

5+ Year Member Top Contributors Of The Month



That shows this in the browser:
/usr/local/lib/perl5/site_perl/5.32/x86_64-cygwin-threads /usr/local/share/perl5/site_perl/5.32 /usr/lib/perl5/vendor_perl/5.32/x86_64-cygwin-threads /usr/share/perl5/vendor_perl/5.32 /usr/lib/perl5/5.32/x86_64-cygwin-threads /usr/share/perl5/5.32

Checking the first location from the terminal, I do see DBI.pm:
$ ll /usr/local/lib/perl5/site_perl/5.32/x86_64-cygwin-threads
total 312
-rwxr-xr-x 1 svc_dpa_sql Domain Users 318199 Nov 17 10:18 DBI.pm*

Brett_Tabke

11:59 pm on Nov 21, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



When you run from the cmd line, are you logged in as root?

I'd think there is a DBI permissions issue then. I'd guess the user group that apache is running under, does not have access to dbi.

Login as the 'user' that is associated with the domain and/or your apache user group and try to run that 4 line tester script with dbi in it.

phranque

12:30 am on Nov 22, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



-rwxr-xr-x

755 should provide execute access for everyone, regardless of file ownership or user/group of the execution environment.

what are the ownership/permissions of the containing directory? (/usr/local/lib/perl5/site_perl/5.32/x86_64-cygwin-threads)

MrDOS

1:20 am on Nov 22, 2022 (gmt 0)

5+ Year Member Top Contributors Of The Month



Thanks again for the responses! I am from (and live in) the Dos/Windows side, so I am not always sure how to proceed.
Let me know if this answers the containing directory permissions:

svc_dpa_sql@IT-SQL-DBA /usr/local/lib/perl5/site_perl/5.32
$ ll
total 0
drwxr-xr-x 1 svc_dpa_sql Domain Users 0 Nov 17 10:18 x86_64-cygwin-threads/

The user that runs the Apache service is the same domain user that I logged in as, and this account is in the Windows Administrators group on this box.

Brett_Tabke

4:36 am on Nov 24, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



try putting this as the 2nd line of the test dbi script:

use CGI::Carp qw (fatalsToBrowser);

That, might fail by itself, but if it works, it should spit an error into your browser.

phranque

7:35 am on Nov 24, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



use CGI::Carp qw (fatalsToBrowser); 

wouldn't that show the same error that was reported in the server error log file?

MrDOS

2:37 pm on Nov 24, 2022 (gmt 0)

5+ Year Member Top Contributors Of The Month



That script fails in the Terminal with:
$ perl mpl2.pl
Can't locate CGI/Carp.pm in @INC (you may need to install the CGI::Carp module) (@INC contains: ...

I get Internal Server Error and a similar message in the Apache error_log when I try that from the web browser.

I found Carp.pm in /usr/share/perl5/5.32 so I tried:
$ perl -I /usr/share/perl5/5.32 mpl2.pl
Can't locate CGI/Carp.pm in @INC (you may need to install the CGI::Carp module) (@INC contains: ...

Brett_Tabke

7:05 pm on Nov 24, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



> wouldn't that show the same error that was reported in the server error log file?

Ya, just thought maybe there would be more info or something.

>Can't locate CGI/Carp

ya, figured that - some systems still have it.

I would try reinstalling dbi from cpan on the command line. That should update the correct user group permissions. Make sure to be logged in as the user associated with apache or the domain you are running under.

Brett_Tabke

7:08 pm on Nov 24, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month




>I want to post httpd.conf

Nah, doesn't sound like a apache error.

MrDOS

7:46 pm on Nov 24, 2022 (gmt 0)

5+ Year Member Top Contributors Of The Month



Thanks again.
I've reinstalled DBI from both cpan and cpanm many times.

Brett_Tabke

2:05 pm on Nov 25, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



So recap:

1- runs from cmd line
2-runs from browser, but only if you take out the DBI line.

Have you successfully connected to a database with the script from the command line? One solution suggested a connection to *sql server is required for dbi/dbd to fire up right. (Not sure that is the case, because I know I have run dbi based scripts that work without a server if you don't call opens/closes to the server)

I've never run into this (that I remember) particular problem before. Doing some Googling, it appears to be a moderately generic error msg that could mean any number of things.

I went down the rabbit hole starting here:
[perlmonks.org...]
[perlmonks.org...]

do a google on it, and it is quite the wide array of solutions:
[google.com...]

What is the flavor of OS?

MrDOS

3:07 pm on Nov 25, 2022 (gmt 0)

5+ Year Member Top Contributors Of The Month



The OS is Windows Server 2016 Standard 10.0.14393
Other scripts are connecting to SQL Server databases OK; it is just when I use DBI that I run into issues in the browser.
I have been to many of those sites before -- I will try again!

One reason I suspect an issue with httpd.conf is that the Apache error changed from:
Can't locate DBI.pm in @INC (you may need to install the DBI module)
to:
Can't locate loadable object for module DBI in @INC
when I made an edit in httpd.conf. I need to go to a backup to see which edit I made :|

For reference, here are all of the uncommented lines from httpd.conf
ServerRoot "/etc/httpd"
Listen 1180
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule dbd_module modules/mod_dbd.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
<IfModule !mpm_prefork_module>
</IfModule>
<IfModule mpm_prefork_module>
LoadModule cgi_module modules/mod_cgi.so
</IfModule>
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
IncludeOptional conf.modules.d/*.conf
<IfModule unixd_module>
</IfModule>
ServerAdmin mlascuola@srhc.com
<Directory />
AddHandler cgi-script .pl
AddHandler server-parsed .html
AllowOverride none
Options Includes FollowSymLinks ExecCGI
</Directory>
DocumentRoot "/srv/www/htdocs"
<Directory "/srv/www/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AddHandler cgi-script .cgi .pl
AddHandler server-parsed .html
AllowOverride None
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "/var/log/httpd/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "/var/log/httpd/access_log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/srv/www/cgi-bin">
AllowOverride None
Options FollowSymLinks ExecCGI
AddHandler cgi-script .pl
AddHandler server-parsed .html
</Directory>
<IfModule headers_module>
RequestHeader unset Proxy early
</IfModule>
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddHandler cgi-script .pl
AddHandler server-parsed .html
</IfModule>
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
IncludeOptional conf.d/*.conf
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

Brett_Tabke

6:46 pm on Nov 25, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Your Perl on your path - is that a system path, or just @inc?
What flavor of Perl? (activestate? strawberry?)
What is the raw path to your perl binary? (mine is at c:\usr\bin\perl.exe). For all my stuff to work I have to have both \usr as well as \usr\bin and also \usr\lib on the path.

Some stuff I would try:
- add this as the 2nd line of the script: push @INC,'.';
That adds current path to script. It can help some times.

-copy the DBI.lib DBI.dll, DBI.pm and DBI.exp to your #!/usr/local/bin/perl directory.
They are in ..\lib\auto\DBI

MrDOS

9:17 pm on Nov 25, 2022 (gmt 0)

5+ Year Member Top Contributors Of The Month



OMG - let me know what you want in your holiday stocking!

1) /usr/local/bin/perl is actually a Junction (is that called a reference here?) to /usr/bin/perl
$ ll /usr/local/bin/perl
lrwxrwxrwx 1 svc_dpa_sql Domain Users 13 Nov 7 13:33 /usr/local/bin/perl -> /usr/bin/perl*

2) Once I copied DBI.dll (I do not have DBI.lib or DBI.exp on my system) to /usr/bin, then I started seeing other errors in the browser itself (no longer in /var/log/httpd/error_log), and it was just a matter of placing .DLLs and, so far, all scripts are working in the browser.

Thanks so much for taking the time to help!

phranque

10:25 pm on Nov 25, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



/usr/local/bin/perl is actually a Junction (is that called a reference here?) to /usr/bin/perl

in unix parlance that would be a symbolic link (or softlink)

the ls command output shows this with the "l" in the permissions string:
lrwxrwxrwx

and with an arrow from the symbolic link to the target:
/usr/local/bin/perl -> /usr/bin/perl

Brett_Tabke

3:21 pm on Nov 26, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Great - glad it worked. There are so many different builds of perl for windows that weird little issues like this are not uncommon. I have 4 different perl builds on my system. I just rename /usr directory to the version of perl that is going to work for this task.