Might be it's too simple for you to reply to. My issue is about cgi and apache web server. Keep it simplistic, I've got a html "form.html" that contains an application inside it. To gain access to it, typing "127...1/form.html" in browser. After clicking "submit" within this html file, it's supposed to adress to "127...1cgi-bincginame.cgi", this content of "cginame.cgi" is really as below:


java mortcal $data

"mortcal" is really a java program calculating and return a HTML page that contains leads to user. I am using apache 2.2 and ubuntu 10.04. The issue is after i click on the "submit" button in "form.html", I acquired these by mistake log:

[Sat Sep 24 15:00:20 2011] [error] (2)No such file or directory: exec of '/usr/lib/cgi-bin/mortcgi.cgi' failed
[Sat Sep 24 15:00:20 2011] [error] [client] Premature end of script headers: mortcgi.cgi

I understand it is because apache can't find "/bin/party" to complete the cgi file. However I will have "/bin/party". It is so strange. Please assist me. Thanks ahead of time.

To complete CGI scripts, you have to configure Apache to permit this, as well as your script needs to stick to the HTTP protocol by delivering back data within the right format, and right permissions, and so on as well as on.

Here is a great tutorial by having an example: http://httpd.apache.org/docs/2.2/howto/cgi.html

... however, I have to say: managing a java program from inside a spend script via Apache is an awful idea, generally. Each request loads the java runtime engine (JRE), runs this program, then unloads it. You will find difficulties with atmosphere, file possession and so forth -- all this is the reason why you will find application servers like tomcat for java. Therefore if you are just trying something, that's fine. If you are thinking this is an excellent method of getting something completed in an expert production atmosphere, I'd reconsider.

As noted, this appears just like a poor method of doing things, but:

  1. Perform the script file permissions allow execution for that web server user?
  2. Are you currently using any security framework for example selinux which may apply additional limitations?

I checked my configuration files. They're ok. And So I stored searching on the internet and lastly I saw this:

"If you have replicated within the script from the Home windows machine, you might be being tripped up by ^M at finish of line. You should use cat -v /usr/lib/cgi-bin/printenv.pl mind -1 to ensure there is not a ^M in the finish from the line. "

Used to do copy my cgi file from home windows! I didn't remember to say it because I didn't think it is a large deal.

Now I've removed the ^M by typing this" :%s/^V^M//g in mire. This issue is resolved. Thanks greatly for the answer, Mr.Harrison and Dark Falcon, Thanks all.