LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Perl/HTML "you have chosen to open....." (https://www.linuxquestions.org/questions/linux-newbie-8/perl-html-you-have-chosen-to-open-4175577635/)

caeaves 04-17-2016 12:19 AM

Perl/HTML "you have chosen to open....."
 
CentOS on VMware.


Because Linux will fight me to the death, even when I follow the book instructions to the letter, I am coming to you for help. I am tasked with building a crappy web site with Perl/Apache etc. I create the .html file and the matching .pl file. I turn on execute permissions. I made a copy of cgi-lib.pl in /usr/share/perl5 and /var/www/cgi-bin. All files are in their respective /var/www/html and /var/www/cgi-bin. Even following the exact steps outlined mine refused to work.

It makes the pretty html page but clicking submit makes the Firefox prompt open telling me "you have chosen to open: ptools.pl which is a Perl script from: http://localhost What should Firefox do with this file?" I don't want it to do anything except show me the output like in the pretty picture in the book. That it will not do.

I have searched the web and the answer is blame the Apache admin server guy. I guess that is me, which means I am doomed. I installed the httpd -y package and started Apache with service httpd start. Followed by chkconfig httpd on. Got the test page when localhost was typed in the address bar. All html test pages worked. Perl CGI is when it all fell apart.





Here is the perfectly functional ptools.html file.

<html>
<head>
<title>Training Wheels</title>
</head>
<body>
<h1>My Favorite Linux Programming Tools</h1>

<form action=/cgi-bin/ptools.pl method="get">

Name: <input type="text" name="user" size=40><p>

Select your favorite scripting language:<br>
<input type="radio" name="language" value="Bash">Bash<br>
<input type="radio" name="language" value="Perl">Perl<br>
<input type="radio" name="language" value="PHP">PHP<br>
<input type="radio" name="language" value="Python">Python<br>
<p>
Select your favorite text editor:<br>
<input type="radio" name="textedit" value="vi">vi<br>
<input type="radio" name="textedit" value="nano">nano<br>
<input type="radio" name="textedit" value="gedit">gedit<br>
<input type="radio" name="textedit" value="emacs">emacs<br>
<p>
<input type="submit" value="Submit form">
<input type="reset" value="Clear all fields">
</form>

</body>
</html>



Here is the ptools.pl file.

#!/usr/bin/perl
require("cgi-lib.pl");

&ReadParse(*input);

print "Content-type: test/html\n\n";
print "
<html>
<body>
Hello <b>$input{'user'}</b><br>
Your favorite scripting language: <b>$input{'language'}</b><br>
Your favorite scripting text editor: <b>$input{'textedit'}</b>
</html>
</body>";

Thanks for looking and helping a passing through Linux user.

cliffordw 04-17-2016 03:26 AM

Hi there, and welcome.

This does look like an Apache problem. It is not recognizing the ptools.pl file as a CGI script it should be executing, so it is offering it for download instead.

This is most likely either because the cgi_module isn't enabled, or the ScriptAlias section in your httpd.conf file is not configured correctly. Have a look at those, and if you're still stuck, let us know which Linux distribution you're running, so we can try and help with further details.

Good luck!

caeaves 04-17-2016 10:59 AM

Thank you for helping. I am using CentOS 7 64 Bit.
Kernel: Linux 3.10.0-327.4.5.el7.x86_64


I followed this tutorial for setting up apache.
http://www.webmo.net/support/apache_centos7.html

# yum -y install perl-CGI was not installed and I thought the day was saved but nothing changed.

All .pl files are in the /var/www/cgi-bin location.

How my httpd.conf is set up.

Quote:

The same rules about trailing "/" apply to ScriptAlias
# directives as to Alias.
#
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

</IfModule>

#
# "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>

Running this http://localhost/cgi-bin/hello.pl works perfectly. Hello World pops up and it's fine. So am I calling it wrong through the html file?

cliffordw 04-18-2016 10:16 AM

Hi again,

In ptools.pl, This looks wrong:

Code:

print "Content-type: test/html\n\n";
Changing it to this solved the problem for me:

Code:

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

caeaves 04-18-2016 10:31 AM

Quote:

Originally Posted by cliffordw (Post 5532860)
Hi again,

In ptools.pl, This looks wrong:

Code:

print "Content-type: test/html\n\n";
Changing it to this solved the problem for me:

Code:

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


Yes, yes, yes yes!!!!! That was a great find. Thank you. Occam's razor for sure. Here I am downloading all sorts of things and reading tons of pages looking for what turned out to be a one letter solution. Since I copy pasted the same thing through all of my .pl files the issue spread. Thanks again.


All times are GMT -5. The time now is 02:07 AM.