0
votes

I have a perl script in /var/cgi-bin directory which executes normally with the url:

localhost/cgi-bin/filename.pl

but when i call the same file through a html file the loaclhost server return a 404 not found error.

code: html file:

<?xml version="1.0"encoding="utf-8"?>
<html>
            <head>
                            <title>light bulbsr form</title>
            </head>
            <body>

<form action="/cgi-bin/bulbs.pl" method="POST">

user name<input type="text" name="myname" size="30"/><br>

select the items:<br>

<input type="checkbox" name="b" value="2.39" /> four100 watt light bulbs  </br>
<input type="checkbox" name="b" value="4.29">  eight 100 watt light bulbs </br>
<input type="checkbox" name="b" value="3.95">  four 100 watt  long life bulbs </br>
<input type="checkbox" name="b" value="7.49"> eight100 watt  long life bulbs </br>

Select the mode of the payment:</br>

<input type ="radio" name="paymode" value="visa" checked="checked"/>Visa<br>
<input type ="radio" name="paymode" value="Master card"/>Master card<br>
<input type ="radio" name="paymode" value="Discover"/>Discover<br>

                            <input type="submit" value="submit order"/>
                            <input type="reset" value="Clear the form"/>
            </body>
</html>

perl file:

#!/usr/bin/perl
use CGI qw(:standard);
use strict;


print header(),start_html ("Bill ");
print p("The total cost:0");br();
print end_html;

the apache2 000-default.conf:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ScriptAlias /cgi-bin/ /var/cgi-bin/
     <Directory "/var/cgi-bin/">
             AllowOverride None
             Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
             Require all granted
     </Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
1
what's the URL of the HTML document? You probably need cgi-bin/filename.pl or /cgi-bin/filename.pl because your HTML file is not in the cgi-bin directory. - simbabque
I hope this is a learning exercise. You're not going to pick up credit card numbers with this, are you? - simbabque
Yes,this is a learning exercise. Plz help!! - Harsh Rewari
You've said the cgi-bin is in /var/cgi-bin. Where is the HMTL file? - simbabque
the html file is in /var/www/html - Harsh Rewari

1 Answers

0
votes

Your form action is "filename.pl". That means the web server will look for "filename.pl" in the same directory as the HTML page containing the form. And that's not where it it. You probably want the full path.

<form action="/cgi-bin/filename.pl">