Using Lubuntu 13.10, Lazarus 1.2, FPC 2.6.2.
This is not a question about where to put a CGI executable or how to execute it. The real question follows after a long preamble which should (with any luck) outline what the answer isn't.
In my baby steps way I learned about Python's simple built-in web servers. Ah! Python is already installed on Lubuntu! So I copied the website I'm working on from WinVista to Lubuntu and put it in a directory called 'www'.
The pages of the website are all static (that's what I'm trying to change, but baby steps...). So I executed this command from a terminal window in the 'www' directory.
python -m SimpleHTTPServer
Now Lubuntu's default Firefox browser can access the local website via either '127.0.0.1:8000/index.htm' (which is what the tutorial I found said) or 'localhost:8000/index.htm' (which I suspected would also work, and it does). All the pages work just like the actual website on my ISP (so: one live website and two local copies, one for Windows and one for Linux).
Incidentally this where I noticed in the terminal window log file that Firefox spontaneously asked the server for 'favicon.ico'. Twice. The server denied this file existed (since it didn't) - '404' both times. Hmm. So I read up on how non-standardised all this is, sighed, created a simple one, and put it in the root directory of all three versions of the website. Firefox likes it. IE9 doesn't. Oh well.
Next is to try to execute CGI program from a shiny new page with its form:
<form method="post" action="cgi-bin/pricelookupcgi.exe">
which I did not expect to work - 'SimpleHTTPServer' does not have CGI capabilities. And it didn't. The server returned a 'POST not supported' message. Baby steps...
Okay, this time I'll try
python -m CGIHTTPServer
instead. Oh, and maybe I should change that 250K Lazarus-generated binary for Windows to the 600K Lazarus-generated binary for Linux as well (oops!).
I still didn't expect this to work. The CGI library module in Python automatically sends a '200 OK' response before it actually tries to execute the script. Makes redirects within a script rather - messy - for one thing. And as my program uses redirects, I figured I'd have to edit that CGI module before things would behave properly. Still, I wanted to see what would happen. Baby steps...
What I got was a message in the browser
The CGI app reports an error:
File not found: '..\template\rateshow.tpl'
The thing about this particular message is that it is not coming from the server. It is coming from my CGI program. Specifically this part:
{ show rudimentary HTML error page }
{ - our own, not the server's }
procedure UIshowerror(const mesg: String);
begin
writeok;
writeln( Output, '<HTML><HEAD><TITLE>CGI APP ERROR</TITLE></HEAD><BODY>' );
writeln( Output, '<P>The CGI application reports an error:</P>' );
writeln( Output, '<H3>' + mesg + '</H3>' );
writeln( Output, '</BODY></HTML>' );
end;
{ check if a file can be accessed }
function canaccess(const fname: String): Boolean;
begin
canaccess := False;
if ( FileExists(fname) ) then
canaccess := True
else
UIshowerror( 'File not found: ' + fname );
end;
which I put in after having trouble with a local IIS7 server. Never did figure out why it happened; never needed to after discovering the 'tinyweb' server (which runs my CGI program just fine under Windows).
But now I see the same or a similar problem is happening with a much less sophisticated web server than IIS. At this point in the program the user input has been accepted and all the calculations done. What it's trying to do now is open an HTML template file and output it after replacing various markers in the template with the results of its calculations (sort of a primitive version of ASP).
Sez I to self, 'Self, this may be a directory separator thingy'. So now I know about 'PathDelim' and how to use it for portability. Nope, not the problem (all the '\'s are changed to '/'s in the error message, though).
Nor is it a case problem - all website filenames are lower case now (one of the first problems I discovered while playing with 'SimpleHTTPServer').
A permissions thingy? Lubuntu's file manager reports 'Anyone' can 'View', 'Only Owner' can 'Change Content' and 'Nobody' can 'Execute'. Which I assume mean 'read, write, execute', respectively. I could even change them using the file manger, but I would have thought universal read access was already sufficient.
So...what next?