anikng has asked for the wisdom of the Perl Monks concerning the following question:
Hellow Monks,
I saw some posts similar to my following doubt. But i couldnt figure it out. So kindly help me (am not an expert).
I have a front end html (with buttons) and a backend PERL cgi script. The code is correct and tested in another windows system.
Now, i placed two files in www folder (under var) in Ubuntu 14.04. But when i clcik the button, instead of runing the cgi, script itself is displayed. Someone kindly help me what changes to be made (in a simple way).
I also attach the contens of front end html and backend test.cgi
Front end.html
<html>
<body>
<h3> <center>TRANSCRIPTION FACTOR FAMILY</center></h3>
<form action="/var/www/test.cgi" method="GET">
<input type="submit" value="ABC">
</form>
</body>
</html>
test.cgi,
#!/usr/bin/perl
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
$q=new CGI;
print "Content-type: text/html\n\n";
@field=$q->param();
$name=$q->param("value");
print<<"OUTPUT";
<html>
<head>
<title> FAMILY SELECTION </title> </head>
+
<body>
<img src="/var/www/bb.jpg" size=100">
<br><br><br><br><br>
<center><table border=0>
<tr><td>
</td></tr>
</table></center>
</body>
</html>
OUTPUT
Thanks,
anikng
Re: CGI SCRIPT ITSELF IS DISPLAYED
by skx (Parson) on Sep 21, 2014 at 08:18 UTC
|
There are two things wrong here:
- The CGI script http://example.com/test.cgi is not being executed.
- The action-element of your FORM is pointing to the wrong thing.
To solve the first problem you need to consult your webserver documentation, there are two ways you can go here - either configure the webserver to execute *.cgi, regardless of location, or copy the script into your cgi-bin directory - which will probably be /usr/lib/cgi-bin, since you mention ubuntu.
If you want to configure CGIs to be globally executed you should start by looking at "a2enmod cgi", or similar.
Secondly your form-action points to /var/www... which is a file reference and not a URL reference. It hsould be updated to point to /test.cgi, or /cgi-bin/test.cgi as appropriate. (You have the same issue with the image you try to print from your CGI-script. You need to learn the difference between a file-path and a URL-path.)
| [reply] |
Re: CGI SCRIPT ITSELF IS DISPLAYED
by Corion (Patriarch) on Sep 21, 2014 at 07:59 UTC
|
Is your webserver configured to execute the CGI file? Are the file permissions on the server set so that the file can be executed?
| [reply] |
Re: CGI SCRIPT ITSELF IS DISPLAYED
by Anonymous Monk on Sep 21, 2014 at 09:14 UTC
|
See https://httpd.apache.org/docs/2.2/howto/public_html.html#cgi / Apache Tutorial: Dynamic Content with CGI and more Copy/paste from Re: To call a .pl file when a button is pressed on a GUI created using Perl CGI (webserver) for the links below Its simple, you need a webserver Why? Because webpages and CGI needs a webserver, thats how it works Its weird that so many folks manage to create a GUI using Perl CGI without understanding this learn about the internet,Web Programming: For Beginners, to get an overall picture of how the internet works, how tcp/ip, sockets, html, ajax, all fit together.... See also Mojolicious::Lite +and jQuery +AJAX + Mojo::Template And a copy-pasta for you:) Also, there are checklists for that , Basic debugging checklist , brian's Guide to Solving Any Perl Problem, CGI Help Guide , Troubleshooting Perl CGI scripts Yes, work through these checklists, when you find a problem on the list, use a solution from the list, when you find a problem not on the list (rare), post the error message and problem description here brian's Guide to Solving Any Perl Problem, CGI Help Guide , Troubleshooting Perl CGI scripts So examine your server configuration and compare to https://httpd.apache.org/docs/2.2/howto/public_html.html#cgi / Apache Tutorial: Dynamic Content with CGI learn about the internet,Web Programming: For Beginners, to get an overall picture of how the internet works, how tcp/ip, sockets, html, ajax, all fit together. Explicitly using Options to permit CGI execution, Apache Tutorial: Dynamic Content with CGI - Apache HTTP Server Version 2.2 : Explicitly using Options to permit CGI execution
| [reply] |
|
<!DOCTYPE html>
<html>
<body>
<h3> <center>TRANSCRIPTION FACTOR FAMILY</center></h3>
<form action="http://localhost/cgi-bin/test.cgi" method="GET">
<input type="submit" value="NAC">
</form>
</body>
</html>
#!/usr/bin/perl
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
$q=new CGI;
print "Content-type: text/html\n\n";
@field=$q->param();
$name=$q->param("value");
print<<"OUTPUT";
<html>
<head>
<title>TRANSCRIPTION FACTOR DATABASE </title>
</head>
<body>
<img src="file:///var/www/html/index.jpeg" height="42
+0" width="420">
<br><br><br><br><br>
<center><table border=0>
<tr><td>
</td></tr>
</table></center>
</body>
</html>
OUTPUT
| [reply] [d/l] [select] |
|
<img src="file:///var/www/html/index.jpeg" height="420" width="420">
That's not how HTTP works with HTML. Every resource generates its own HTTP request. You will need to serve the image via HTTP too, instead of using the file:// protocol.
You will need to use a file path that is relative to your CGI script. Maybe
<img src="index.jpeg" height="420" width="420">
already is enough, because the image lives in the same folder as your HTML page.
This has very little to do with Perl. I recommend you try it out with a static HTML page and a static image file first. | [reply] [d/l] [select] |
|
However, still am not able to generate a figure. Instead, a blank layout is shown.I know that it is something related to file pointing the figure.Kindly suggest me. anikng Go back and read more about urls, file:... is not http://localhost
| [reply] |
Re: CGI SCRIPT ITSELF IS DISPLAYED
by sundialsvc4 (Abbot) on Sep 22, 2014 at 14:24 UTC
|
This isn’t a Perl specific issue ... it is, literally, a web-in-general FAQ.
The root cause of your problem is that there is no AddHandler directive (perhaps in an .htaccess file ...) which instructs Apache that a reference to this particular file (-type), in this particular directory, means that the content of the file should be executed, rather than served as though it were mere-text.
| |
|
|