Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

CGI SCRIPT ITSELF IS DISPLAYED

by anikng (Initiate)
on Sep 21, 2014 at 07:46 UTC ( [id://1101435]=perlquestion: print w/replies, xml ) Need Help??

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

Replies are listed 'Best First'.
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.)

    Steve
    --
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?

Re: CGI SCRIPT ITSELF IS DISPLAYED
by Anonymous Monk on Sep 21, 2014 at 09:14 UTC
      Thanks for the suggestion..!! I managed to run the cgi script on my server by configuring the file (1./etc/apache2/sites-enabled/000-default.conf 2./etc/apache2/apache2.conf) . 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

      Some information, My html file is in var/www/html folder. CGI script is under usr/lib/cgi-bin (i use this path to the configuration file for cgi configuration).

      <!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
        <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.

        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

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1101435]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-25 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found