1

I was trying to invoke a CGI program via an html file. But got stuck for the error "file not found".

I am trying the same program as in the following site:

http://highered.mcgraw-hill.com/sites/dl/free/0070635463/372169/CGI_with_PERL.pdf

Please find below the html file:

<html> <head>
<title>The Employee Database</title>
Appears on title bar
</head>
<body>
<h1> Employee Form </h1>
Appears in a large bold font
<hr>
Adds a horizontal rule
<form action=”http://localhost/~ravbholua/emp_add.pl” method=get>
Emp-id: <input type=”text” name=”empid” size=4> <br>
Name: <input type=”text” name=”ename” size=30> <br>
Designation: <input type=”text” name=”desig” size=15> <br>
Department: <input type=”text” name=”dept” size=15> <br>
Dateoffuse: <input type=”text” name=”dtbirth” size=10> <br>
noSalary: <input type=”text” name=”salary” size=10> <br> <br>
<center>
<input type=submit value=”Add”>
The Add button is centered
</center>
</form>
</body>
</html>

To work in my system, I changed (changed than what is mentioned in the link above) the path of the CGI program file. The path is now: http://localhost/~ravbholua/emp_add.pl

When I click on Add button, I get error that 'file not found'. Please see attachment.

enter image description here

Please have a look at the form (attachment).

enter image description here

Why it is not finding the file which is in the home directory of username "ravbholua"? These 2 attachments w'd help you to catch the issue.

I have the same query in the below link but isn't resolved yet. Please look through it. http://www.linuxquestions.org/questions/linux-server-73/web-page-not-able-to-find-cgi-program-file-4175476182/

Ravi
  • 3,823
  • 1
    To be able to get help here your should really 1) give all the information you've given on the other site (no-one likes having to do cross-reference on the other site), 2) check the content and post here the HTTP server logs when you test the CGI, 3) fix the first link in the post and 4) fix the screenshots which are way too small to anyone to get anything from them. – zagrimsan Sep 15 '13 at 14:57
  • The first guess, though, is that the script is not finding some of the files it refers to. Remember that HTTP servers usually restrict their content under the document root directory. However, it's just a wild guess without seeing the logs and the script (if you can post the script, it would make things much easier - if it's very long it might be enough to show the parts which open/read/write files). – zagrimsan Sep 15 '13 at 14:59
  • By localhost/~ravbholua/ are you trying to access your $HOME? That won't work, you should have the perl script in the same directory tree as you place the HTML file. – terdon Sep 15 '13 at 15:31
  • By the way - I want to view those screen shots, but they only show up as very tiny images on my browser - not sure if I'm missing the way to view them full size. Clicking on them had no effect. – ash Sep 16 '13 at 06:10
  • Thank you @zagrism for showing me the mistakes. I have fixed the point no. 3 and ponit no. 4 of your 1st comment. That means: fixed the 1st link and fixed the 2 screenshots. – Ravi Sep 16 '13 at 07:55
  • @terdon I have kept the html file, perl script and other related files in the same directory .i.e. home directory /home/ravbholua. Is this a problem? – Ravi Sep 16 '13 at 07:58
  • @ash Yes there was some problem with the photoes. I don't know why it was very tiny. I have reloaded them. Thank you for viewing my post and sorry for the problem. – Ravi Sep 16 '13 at 12:47
  • OK, we need to know what server you are using and how you have configured it. This is no a problem with the HTML, it is an issue of configuring your server to allow execution of scripts in a specific directory. – terdon Sep 16 '13 at 13:42
  • @terdon , I am new to html. I haven't configured anything there. It may look funny but frankly I am not aware of what server is there. (I hope you may be interested to know whether it's http server or ftp server, etc). Please guide me how to find that. I checked if http server is running by ps -ef | grep http. Many lines were displayed but I couldn't be sure. As earlier told you, I am new to running an html program. If you say I w'd add the output of the ps command in my 1st post. – Ravi Sep 17 '13 at 04:01
  • OK, we need to know 1) What OS you have (looks like Ubuntu Linux but which version?) 2) the output of service apache2 status, 3) Read up on the documentation, you are missing a lot of information and it is going to be very hard to answer before you understand a bit more. Start here and go on to here. Pay special attention to sites_enabled, sites_available and the cgi-bin directories. – terdon Sep 17 '13 at 04:32
  • Thanks terdon! Yes, give me time and once I read the links you have sent, I w'd update. Regarding your 1st 2 queries: 1) Ubuntu 13.04 is my OS. 2)The output is: apache2: unrecognized service – Ravi Sep 17 '13 at 08:02
  • @Ravi OK, that's one problem right there, as you will see in the links I sent, you need to install a webserver (like apache) in order to serve websites. – terdon Sep 17 '13 at 14:40

1 Answers1

2

The web server doesn't typically translate ~ravbholua to your user home directory (it would take special configuration to make it do so), nor would I recommend attempting any method to get it to do so as that makes the entire contents of the home directory visible through the server - a major security risk.

Try creating a public_html directory under the home directory and place the file there. Note, though, that the web server may actually rewrite the location of CGI scripts, or refuse to treat a file at certain locations as CGI scripts - again, for security. It depends on the web server configuration. Likewise for the actual mapping of ~ravbholua - it may not go to that users $HOME/public_html directory.

Looking at the web server log file under /var/log, and probably named something like http.log or apache.log, may give errors or information that could help track down the root cause of this issue. If that doesn't work, tracing the web server using strace can help - although this can be tricky to do. The paths to all files accessed by the webserver can be seen via strace.

ash
  • 7,260