LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-17-2016, 12:19 AM   #1
caeaves
LQ Newbie
 
Registered: Apr 2015
Posts: 6

Rep: Reputation: 0
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.
 
Old 04-17-2016, 03:26 AM   #2
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 503

Rep: Reputation: 189Reputation: 189
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!
 
Old 04-17-2016, 10:59 AM   #3
caeaves
LQ Newbie
 
Registered: Apr 2015
Posts: 6

Original Poster
Rep: Reputation: 0
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?
 
Old 04-18-2016, 10:16 AM   #4
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 503

Rep: Reputation: 189Reputation: 189
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";
 
Old 04-18-2016, 10:31 AM   #5
caeaves
LQ Newbie
 
Registered: Apr 2015
Posts: 6

Original Poster
Rep: Reputation: 0
Thumbs up

Quote:
Originally Posted by cliffordw View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl - Can't use string ("html") as an ARRAY ref while "strict refs" OldGaf Programming 9 08-11-2009 11:14 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
unable to open "compiled HTML Help file" rahul_khare15 Linux - Newbie 1 11-07-2007 12:48 AM
How to "Search & Replace" in html files using Perl? rebel Red Hat 8 04-09-2005 12:58 PM
Compiling KDE 3.2.0 - "Can't open perl script "/dcopidlng/kalyptus" linuxgamer09483 Linux - Software 3 04-09-2004 08:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration