Welcome to WebmasterWorld Guest from 35.171.45.91

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Perl script shows source code in browser

     
4:50 am on Jan 2, 2019 (gmt 0)

New User

joined:Jan 2, 2019
posts: 15
votes: 1


Hello all, and happy new year!

I am new to perl and cgi programming so please bear with me. I have quite a lot of legacy code that is written in perl, and was working fine at a previous employer, who set up all of the infrastructure before my arrival. I'd like to leverage all of this code to a new employer, so I set up a similar environment. Any .pl script I try to run from the browser does not work as expected, even after hours of research.

Here's what I have set up OK so far:

Cygwin on Windows server 2016 std.
Apache/2.4.29 (Unix)
Any .html runs fine on my running Apache server. When I try to run a .pl script from the browser, it returns source code, instead of expected output.

I've tried all of the recommendations I've found, such as:
1) Adding Options Includes FollowSymLinks to the <Directory /> section of httpd.conf
2) Adding Options Includes FollowSymLinks ExecCGI to the <Directory "/srv/www/htdocs"> section of httpd.conf
3) Checking execute permissions of the .pl script
4) Updated the !# 1st line in the .pl script to point to the results of which perl from the bash prompt

Does anyone have any suggestions as to where to go from here? I suspect that my issue is related to an initial test where I installed all of these using a different user, then uninstalled and reinstalled using a new user.

Thanks for any pointers!

[edited by: phranque at 6:10 am (utc) on Jan 2, 2019]
[edit reason] see Perl forum Charter [webmasterworld.com] [/edit]

6:07 am on Jan 2, 2019 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11868
votes: 244


welcome to WebmasterWorld [webmasterworld.com], MrDOS!

is the mod_cgi(d) module loaded?
6:51 am on Jan 2, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15932
votes: 885


What, if any, AddHandler and/or SetHandler directives do you currently have in place?

:: grasping at straws ::
3:30 pm on Jan 2, 2019 (gmt 0)

New User

joined:Jan 2, 2019
posts: 15
votes: 1


Thanks for the replies! I am not familiar with mod_cgi -- is that something I would install with the CygWin installer?

In httpd.conf, I have
AddHandler cgi-script .cgi .pl under <Directory "/srv/www/htdocs">
AddHandler cgi-script .cgi .pl under <Directory "/srv/www/cgi-bin">
and
AddHandler server-parsed .html under <IfModule mime_module>

Should AddHandler server-parsed .html be in a different section?

Thanks!
4:40 pm on Jan 2, 2019 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4558
votes: 363


I haven't seen it mentioned here and I'm guessing that these things were checked first before anything but have you checked to see that the perl version installed is compatible with the script? Is there a variables file that needs configuration/options settings?
5:09 pm on Jan 2, 2019 (gmt 0)

New User

joined:Jan 2, 2019
posts: 15
votes: 1


Would I need any of that with such a simple script, such as:
#!/usr/local/bin/perl.exe

print "Content-type:text/html\n\n";

print "<html><head><title>My First Script</title></head>\n\n";
print "<body>\n";
print "<p>Hello world!</p>\n";
print "</body></html>";
9:58 pm on Jan 2, 2019 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Dec 15, 2003
posts:2645
votes: 7


I am pretty sure that in Apache24 that you don't enable modules by un-commenting them in the conf file.

I think best practice says to enable them using the a2enmod command.

Have you tried using it? It will either tell you the mod doesn't exist, is already enabled, or that it was successfully enabled and to restart apache.
10:57 pm on Jan 2, 2019 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11868
votes: 244


i would search for the "cgi" string in your server config file and examine everything you discover until you understand it.

you should especially read all of the mod_cgi documentation [httpd.apache.org] and if you are running in a multi-threaded server environment also absorb the mod_cgid documentation [httpd.apache.org].
2:26 pm on Jan 3, 2019 (gmt 0)

New User

joined:Jan 2, 2019
posts: 15
votes: 1


Thanks for the replies. I cannot locate the a2enmod script. I searched in the Cygwin install, and tried to load it with cpan, but cpan does not know what it is.
3:13 pm on Jan 3, 2019 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4558
votes: 363


I think best practice says to enable them using the a2enmod command.
it appears it is not a script but a command. Sorry I can't help with that but it always helps to be looking for the right thing.
5:20 pm on Jan 3, 2019 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Dec 15, 2003
posts:2645
votes: 7


It is a command, you have to run it from a terminal command line.

sudo a2enmod rewrite (enables mod_rewrite)

sudo a2enmod perl (enables mod_perl2)

Make sure you reload or restart apache after:
sudo service apache2 reload
sudo service apache2 restart


If you get a "module not found" error when you run a2enmod then you will need to install it first. You can do that from the command line as well.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install perl
5:37 pm on Jan 3, 2019 (gmt 0)

New User

joined:Jan 2, 2019
posts: 15
votes: 1


Thanks for your patience. I have not been able to find the command a2enmod. Here's the results:
USERNAME@SQLMONITOR /etc/httpd/conf
$ sudo a2enmod rewrite
-bash: sudo: command not found

USERNAME@SQLMONITOR /etc/httpd/conf
$ a2enmod rewrite
-bash: a2enmod: command not found


However, I noticed that in my httpd.conf file, the LoadModule here was commented out.
<IfModule mpm_prefork_module>
#LoadModule cgi_module modules/mod_cgi.so
</IfModule>

When I removed the #, and restart the service, I now receive an "Internal Server Error" from the browser, which I feel is progress!

In /etc/httpd/logs/error_log, the last error is:
[cgi:error] [pid 4980] [client ::1:56108] AH01215: (13)Permission denied: exec of '/srv/www/cgi-bin/mpl.pl' failed: /srv/www/cgi-bin/mpl.pl

I checked permissions on that file, and they look correct to me (and the file name appears green, like other executables):
USERNAME@SQLMONITOR /etc/httpd/conf
$ ll /srv/www/cgi-bin/mpl.pl
-rwxr-xr-x 1 USERNAME Domain Users 205 Jan 1 20:28 /srv/www/cgi-bin/mpl.pl*

I will look more at permissions, maybe from the Windows side...



[edited by: not2easy at 6:47 pm (utc) on Jan 3, 2019]
[edit reason] privacy/security USERNAME replace [/edit]

5:42 pm on Jan 3, 2019 (gmt 0)

New User

joined:Jan 2, 2019
posts: 15
votes: 1


The issue with the test script is solved!

I changed the first line from
#!/usr/local/bin/perl.exe
to
#!/usr/local/bin/perl
And, I am in business. Thanks for all of your assistance!
9:26 pm on Jan 3, 2019 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Dec 15, 2003
posts:2645
votes: 7


Congrats MrDos!

Just for clarification for anyone coming back who may be trying to use the a2enmod commands. What OS/distribution are you on? I am mildly curious as to why those commands didn't work, but maybe they aren't available in Apache24 on certain Operating Systems.
10:26 pm on Jan 3, 2019 (gmt 0)

New User

joined:Jan 2, 2019
posts: 15
votes: 1


Please let me know if there's anything OS-related additional I can add to the original post.

Now running the prod scripts, I am seeing a different error, but at least I have something to look into:
AH01215: Can't locate DBI.pm in @INC (you may need to install the DBI module)

I suspect this is because when DBI was installed, it was under a different security context. I tried running install DBI again from cpan, but it just tells me that I'm up to date.

With all I've got under my belt, I may bite the bullet and re-install everything under the proper security context.
12:13 am on Jan 4, 2019 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11868
votes: 244


perl -V


this will show you the value of @INC which is the array of perl libraries available.

then find DBI.pm and make sure it's in one of those directories.
11:24 am on Jan 4, 2019 (gmt 0)

New User

joined:Jan 2, 2019
posts: 15
votes: 1


I did that, and DBI.pm was not in one of those directories. DBI requires more than just DBI.pm, there's a folder structure as well. I copied DBI.pm and the folder structure to one of the paths in @INC, yet receive a similar error message (I am on a different PC now, so I can't get the exact message).

The beauty of completely re-installing a system is that it goes faster the 2nd time, right? :)