Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-04

CGI under Linux using FCL-Web

12 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Christian Kranich

Hello All,

I just started to use FPC in a project requiring a Webinterface. When porting the Lazarus/Win32 fpc-web examples (worked fine) to X86/Linux(Ubuntu) and Arm-Linux, I started to struggle.

Under Linux, the cgi program terminates w/o any output and w/o any errormessages. So Apache complains about premature page end.

=> Is there anything special to consider when using fcl-web under Linux?

=> The bread and butter cgi example (mini.pas) did run, but I like the concept of FCL-Web offering scalability between CGI, FastCGI, Apache Module and do not want to reinvent the wheel...

Currently I started copying the fcl-web sources to project folder and pinpointing with writelns to crosscheck what is running and what is not.

Kind Regards,

Christian Kranich

Reply by email

Unknown author
to Christian Kranich
Christian Kranich wrote 11 lines
Hello All, I just started to use FPC in a project requiring a Webinterface. When porting the Lazarus/Win32 fpc-web examples (worked fine) to X86/Linux(Ubuntu) and Arm-Linux, I started to struggle. Under Linux, the cgi program terminates w/o any output and w/o any errormessages. So Apache complains about premature page end. => Is there anything special to consider when using fcl-web under Linux?

Yes.

* Do not use the crt, video or keyboard units.
* Do not attempt I/O to standard input/output/error.

Show quoted text 6 lines
=> The bread and butter cgi example (mini.pas) did run, but I like the concept of FCL-Web offering scalability between CGI, FastCGI, Apache Module and do not want to reinvent the wheel... Currently I started copying the fcl-web sources to project folder and pinpointing with writelns to crosscheck what is running and what is not.

Check the error log of apache.
It will contain the error output of the CGI script.

Michael.

Reply by email

Leonardo M. Ramé
to Unknown author

Another tip for linux/unix. Try to run the CGI program from the command line, it should output something similar to this:

Exception at 0000000000497B3A: Exception:
No REQUEST_METHOD passed from server.

Otherwise there's an error in your code.

Leonardo M. Ramé
http://leonardorame.blogspot.com

Show quoted text 44 lines
________________________________ From: "" To: FPC-Pascal users discussions Sent: Wednesday, April 4, 2012 8:42 AM Subject: Re: [fpc-pascal] CGI under Linux using FCL-Web On Wed, 4 Apr 2012, Christian Kranich wrote: > Hello All, > > I just started to use FPC in  a project requiring a Webinterface. > When porting the Lazarus/Win32 fpc-web examples (worked fine) > to X86/Linux(Ubuntu) and Arm-Linux, I started to struggle. > > Under Linux, the cgi program terminates w/o any output and w/o any > errormessages. So Apache complains about premature page end. > > => Is there anything special to consider when using fcl-web under > Linux? Yes. * Do not use the crt, video or keyboard units. * Do not attempt I/O to standard input/output/error. > => The bread and butter cgi example (mini.pas) did run, but I like the > concept of FCL-Web offering scalability between CGI, FastCGI, Apache Module > and do not want to reinvent the wheel... > > Currently I started copying the fcl-web sources to project folder and pinpointing > with writelns to crosscheck what is running and what is not. Check the error log of apache. It will contain the error output of the CGI script. Michael. _______________________________________________ fpc-pascal maillist  -  http://lists.freepascal.org/mailman/listinfo/fpc-pascal  

Reply by email

Unknown author
to Leonardo M. Ramé
Leonardo M. Ramé wrote 6 lines
Another tip for linux/unix. Try to run the CGI program from the command line, it should output something similar to this: Exception at 0000000000497B3A: Exception: No REQUEST_METHOD passed from server. Otherwise there's an error in your code.

Better yet, you can test CGI programs with the testcgiapp program that is located in the fcl-web sources. developed specially to test such things.

Michael.

Show quoted text 53 lines
Leonardo M. Ramé http://leonardorame.blogspot.com > ________________________________ > From: "" > To: FPC-Pascal users discussions > Sent: Wednesday, April 4, 2012 8:42 AM > Subject: Re: [fpc-pascal] CGI under Linux using FCL-Web > > > > On Wed, 4 Apr 2012, Christian Kranich wrote: > >> Hello All, >> >> I just started to use FPC in  a project requiring a Webinterface. >> When porting the Lazarus/Win32 fpc-web examples (worked fine) >> to X86/Linux(Ubuntu) and Arm-Linux, I started to struggle. >> >> Under Linux, the cgi program terminates w/o any output and w/o any >> errormessages. So Apache complains about premature page end. >> >> => Is there anything special to consider when using fcl-web under >> Linux? > > Yes. > > * Do not use the crt, video or keyboard units. > * Do not attempt I/O to standard input/output/error. > >> => The bread and butter cgi example (mini.pas) did run, but I like the >> concept of FCL-Web offering scalability between CGI, FastCGI, Apache Module >> and do not want to reinvent the wheel... >> >> Currently I started copying the fcl-web sources to project folder and pinpointing >> with writelns to crosscheck what is running and what is not. > > Check the error log of apache. > It will contain the error output of the CGI script. > > Michael. > _______________________________________________ > fpc-pascal maillist  -  > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > > >   _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Christian Kranich

Michael,

Thank you for the fast response!
and
Many thanks for the _lots_ of work you have done for the project!! (Have the Lazarus and FPC books asside, but want to use the first direct contact for a BIG thank you...)

The apache error log said
Premature end of script headers
(because the script sent absolute nothing)
If I had debug writelns in the code, it complained about misformed header format - showing the first debug output line)

Maybee I am looking on the wrong end: maybee the code is not able to load the template html files and
no template file = no output.
will crosscheck.

Kind Greetings from Vienna,

Christian

Reply by email

Christian Kranich

Hello Michael,
Hello Leonardo,

Thx for further suggestions:
- I did this already (starting from commandline):
In windows it came with an exception (like in leonardo's post) Under Linux it returns w/o _any_ output (not even an errormessage) At first I suggested any not compatible unit and commented them out one by one - but this wasn't the source of the issue BTW: I use the following units
SysUtils,Sockets,Classes,INIFiles,fpCGI(added, not sure if necessary), httpdefs,fpHTTP,fpWeb

- I will tryout the cgi testenviroment. Thx for advice, Michael

Kind Regards,

Christian

Reply by email

leledumbo
to Christian Kranich: Thank you for the fast response! and Many thanks for the _lots_ of work you have done for…
If I had debug writelns in the code, it complained about misformed

header format - showing the first debug output line)

michael said:
* Do not attempt I/O to standard input/output/error.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/CGI-under-Linux-using-FCL-Web-tp5617564p5617618.html Sent from the Free Pascal - General mailing list .

Reply by email

Christian Kranich
to Unknown author: Better yet, you can test CGI programs with the testcgiapp program that is located in the…

Hello All,

1) Sorry, I posted no follow ups but fress posts (twice) before noticing. Will not repeat this.

2) just tried testcgiapp --input=mycgi.cgi
This also returns silently w/o any other output.
The path to the htmls is also valid.

Where and how is the CGI input processed?

I see only a TFPWebmodule type object in my code
(and the DataModuleRequest method to handle the request..) and a RegisterHTTPModule() in the main of the program.

Is there anything that I need to initialize(which might be done correctly under Windows but needs an extra step under Linux)?

Kind Regards,

Christian

Reply by email

Christian Kranich
to leledumbo: header format - showing the first debug output line) michael said: * Do not attempt I/O…
Show quoted text 7 lines
> If I had debug writelns in the code, it complained about misformed header format - showing the first debug output line) michael said: * Do not attempt I/O to standard input/output/error.

Hello,

Thx for the hint: I have already removed the writelns. (I was already aware that standard console out in the case of a CGI belongs _only_ to webpage output)

Kind Regards,

Christian

Reply by email

Unknown author
to Christian Kranich: 1) Sorry, I posted no follow ups but fress posts (twice) before noticing. Will not repeat…
Christian Kranich wrote 17 lines
Hello All, 1) Sorry, I posted no follow ups but fress posts (twice) before noticing. Will not repeat this. 2) just tried testcgiapp --input=mycgi.cgi This also returns silently w/o any other output. The path to the htmls is also valid. Where and how is the CGI input processed? I see only a TFPWebmodule type object in my code (and the DataModuleRequest method to handle the request..) and a RegisterHTTPModule() in the main of the program. Is there anything that I need to initialize(which might be done correctly under Windows but needs an extra step under Linux)?

You need to fill DataModuleRequest with code; It should put something in response, and then call Response.SendResponse. If you don't, nothing will happen.

Michael.

Reply by email

Christian Kranich
to Unknown author
You need to fill DataModuleRequest with code; It should put something in response, and then call Response.SendResponse. If you don't, nothing will happen.

The source of the problem might be located in the unit between my ears ;-O

Looks as if I misunderstood something.
- FCL-Web is a Lazarus based unit. So Lazarus takes care of creating and initializing the objects (So the DataModule) Just wondering why I still got some Lazarus functionality in when saving the data module unit code as a pas file and compiling under fpc.
- So my working enviroment was Lazarus specific (and not Win32) and my not working version was FPC (and not caused by Linux)
- Will boot up the windows again and verify

Show quoted text 6 lines
Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Christian Kranich
to Christian Kranich

==== Case closed ====

I simply was not aware that a certain amount of objects must be alive in an application to use FCL-WEB / CGI. If based (again) on the Lazarus samples and a Lazarus created 'CGIApplication' (with a Webmodule Form) - then it works just fine :-)

Thx again for the fine support and greetings to all that 'Pascaleros' out there! Hope I will soon be able to contribute something(most likely about ARM9 embedded linux)

Christian

Reply by email