Sign in Join

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

Mailing lists / lazarus / 2014-07

Developing with fcl-web

14 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Reimar Grabowski

Hi,

first of all, sorry if the information is out there, but I did not find anything usefull to help me along.

I need to build a server-side application (fcgi is my choice) that gets send some json, processes it and communicates with a mysql database, simple enough. Looks like all this is perfectly doable without any problems with Lazarus and fcl-web, at least the 'gets send some json and processes it'-part I have already done for another project. But it was a pain to develop.
For such kind of projects I am used to Java and development in Eclipse. My major problem with Lazarus is where is my server? In Eclipse I just configure my Tomcat or whatever other container I want to use, press 'run on server' and voila, eclipse starts Tomcat and my application with full logging working inside the IDE to be found at 'http://localhost:8080/myapp'. If I need breakpoints or single stepping, I just start the server in debug mode and all is well. So how do I configure Lazarus to do about the same? I found some mentioning of fpembweb or lazaruswebdesign packages but nothing concrete about where to find or how to use them. Surely some of you guys do such kind of development with Lazarus and I cannot believe that everybody runs a local apache and copies his executable around after every compile (my apache is on a VM which made it even more work to copy the files around and there was no debugging capability to speak of). So it boils down to let Lazarus run the fcgi app (can be another app type if it is easy to switch it to fcgi for deployment) on an (embedded) server, with logging output shown in the IDE and the option to use a debugger with breakpoints and single stepping.

Thanks for any help
R.

Reply by email

Michael Van Canneyt
to Reimar Grabowski
Reimar Grabowski wrote 9 lines
Hi, first of all, sorry if the information is out there, but I did not find anything usefull to help me along. I need to build a server-side application (fcgi is my choice) that gets send some json, processes it and communicates with a mysql database, simple enough. Looks like all this is perfectly doable without any problems with Lazarus and fcl-web, at least the 'gets send some json and processes it'-part I have already done for another project. But it was a pain to develop. For such kind of projects I am used to Java and development in Eclipse. My major problem with Lazarus is where is my server?

That depends.

In Eclipse I just configure my Tomcat or whatever other container I want to use, press 'run on server' and voila, eclipse starts Tomcat and my application with full logging working inside the IDE to be found at 'http://localhost:8080/myapp'. If I need breakpoints or single stepping, I just start the server in debug mode and all is well. So how do I configure Lazarus to do about the same?

It depends on how you set it up.

I found some mentioning of fpembweb or lazaruswebdesign packages but nothing concrete about where to find or how to use them. Surely some of you guys do such kind of development with Lazarus and I cannot believe that everybody runs a local apache and copies his executable around after every compile (my apache is on a VM which made it even more work to copy the files around and there was no debugging capability to speak of). So it boils down to let Lazarus run the fcgi app (can be another app type if it is easy to switch it to fcgi for deployment) on an (embedded) server, with logging output shown in the IDE and the option to use a debugger with breakpoints and single stepping.

There are 2 options:

1. Use embedded server to do the debugging; that part is easy, it's like running a normal executable. You don't need apache for this.

2. You can run the fastcgi server if you use mod_fastcgi.so, but then you must use the ExternalFastCGIServer option, and configure the fastcgi application to listen on this port:

In Apache, configure
FastCgiExternalServer /home/michael/public_html/testht -host 127.0.0.1:10020 -idle-timeout 3 -flush Here 10020 is the port to listen on, and /home/michael/public_html/testht is the URL that will be the 'base' url for your fastcgi app.

In that case, your fastcgi application must be configured to listen on the same port: Set
Application.Port:=10020;
in the project source file.

Restart apache, run your executable, and do a request through the browser. That's it.

Note that you cannot do this with the mod_fcgid module. I do believe that in Apache 2.4, mod_proxy can handle this situation, but I haven't tried yet.

Michael.

Reply by email

ABorka
to Michael Van Canneyt

There is some information on what Michael mentions below here:

http://forum.lazarus.freepascal.org/index.php/topic,13312.15.html

It might help a little. The linked post has some explanation on the different (3 ways) FCGI solutions with apache and fpc/lazarus.

AB

Michael Van Canneyt wrote 82 lines
On Sat, 26 Jul 2014, Reimar Grabowski wrote: > Hi, > > first of all, sorry if the information is out there, but I did not > find anything usefull to help me along. > > I need to build a server-side application (fcgi is my choice) that > gets send some json, processes it and communicates with a mysql > database, simple enough. > Looks like all this is perfectly doable without any problems with > Lazarus and fcl-web, at least the 'gets send some json and processes > it'-part I have already done for another project. > But it was a pain to develop. > For such kind of projects I am used to Java and development in Eclipse. > My major problem with Lazarus is where is my server? That depends. > In Eclipse I just configure my Tomcat or whatever other container I > want to use, press 'run on server' and voila, eclipse starts Tomcat > and my application with full logging working inside the IDE to be > found at 'http://localhost:8080/myapp'. > If I need breakpoints or single stepping, I just start the server in > debug mode and all is well. > So how do I configure Lazarus to do about the same? It depends on how you set it up. > I found some mentioning of fpembweb or lazaruswebdesign packages but > nothing concrete about where to find or how to use them. > Surely some of you guys do such kind of development with Lazarus and I > cannot believe that everybody runs a local apache and copies his > executable around after every compile (my apache is on a VM which made > it even more work to copy the files around and there was no debugging > capability to speak of). > So it boils down to let Lazarus run the fcgi app (can be another app > type if it is easy to switch it to fcgi for deployment) on an > (embedded) server, with logging output shown in the IDE and the option > to use a debugger with breakpoints and single stepping. There are 2 options: 1. Use embedded server to do the debugging; that part is easy, it's like running a normal executable. You don't need apache for this. 2. You can run the fastcgi server if you use mod_fastcgi.so, but then you must use the ExternalFastCGIServer option, and configure the fastcgi application to listen on this port: In Apache, configure FastCgiExternalServer /home/michael/public_html/testht -host 127.0.0.1:10020 -idle-timeout 3 -flush Here 10020 is the port to listen on, and /home/michael/public_html/testht is the URL that will be the 'base' url for your fastcgi app. In that case, your fastcgi application must be configured to listen on the same port: Set Application.Port:=10020; in the project source file. Restart apache, run your executable, and do a request through the browser. That's it. Note that you cannot do this with the mod_fcgid module. I do believe that in Apache 2.4, mod_proxy can handle this situation, but I haven't tried yet. Michael. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

leledumbo
to Reimar Grabowski: first of all, sorry if the information is out there, but I did not find anything usefull…
My major problem with Lazarus is where is my server? So how do I configure Lazarus to do about the same?

Up to you. Apache, nginx, any other you've ever heard of, fphttpserver (embedded), the choice is yours. The last is capable of debugging from IDE. If you use the Lazarus wizard, you should've found it in the application type selection dialog. But actually they only differ in uses clause (fpcgi, fpfcgi, fphttpapp), everything else is the same. Well, maybe you need to set Port as well but that's all. Practically this applies to ALL fcl-web examples, so you can try it yourself.

View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Developing-with-fcl-web-tp4038075p4038085.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

Reimar Grabowski
to leledumbo
Show quoted text 7 lines
> My major problem with Lazarus is where is my server? > So how do I configure Lazarus to do about the same? fphttpserver (embedded), the choice is yours. The last is capable of debugging from IDE. If you use the Lazarus wizard, you should've found it in the application type selection dialog. But actually they only differ in uses clause (fpcgi, fpfcgi, fphttpapp), everything else is the same.

So now we are getting somewhere. The embedded server is embedded inside the application and not inside lazarus, good to know. I already found something that looked to be usefull 'HTTP server Application' but I was not sure about the relations to '(Fast)CGI Application' and what I had to do to transfer one into the other. If it's really just changing the uses clause it would be easy enough. I tried this on my older CGI Application, changing the uses clause in the .lpr file to 'fphttpapp'. Compiled without a problem but of course I could not run it in Lazarus since the run button/menu entry is disabled. Running on the command line gave a socket error which looks like it is working (perhaps changing the port from 80 to something else fixes this).

To recap:
1. I start with a 'HTTP Server Application' to enable my run button/entry since the other two CGI/FCGI disable it.
2. Do my coding/debugging as usual all inside Lazarus.
3. For deployment I change the project to a FCGI one by just replacing the mentioned unit and compiling it.
4. The resulting executable can be put on my Apache on my VM.
5. I am happy.
6. ???
7. Profit

If it's that simple why is it that hard to get that information. Please, tell me I am stupid and there is a wiki page that I just did not find.

Thanks alot.
R.

Reply by email

Reimar Grabowski
to Michael Van Canneyt: That depends. It depends on how you set it up. There are 2 options: 1. Use embedded…
There are 2 options: 1. Use embedded server to do the debugging; that part is easy, it's like running a normal executable. You don't need apache for this.

That's what I am looking for. The 'use embedded server' part is what I failed to understand how to do. But leledumbos mail (hopefully) cleared things up. I was expecting the server, to be started by Lazarus and not that it is a different option in the 'New Project' wizard.

2. You can run the fastcgi server if you use mod_fastcgi.so, but then you must use the ExternalFastCGIServer option, and configure the fastcgi application to listen on this port:

Although this is not what I am currently looking for, it's appreciated for future reference. It's always good to have options.

Thanks.
R.

Reply by email

leledumbo
to Reimar Grabowski: On Sat, 26 Jul 2014 10:56:33 -0700 (PDT) So now we are getting somewhere. The embedded…
I tried this on my older CGI Application, changing the uses clause in the

.lpr file to 'fphttpapp'. Compiled without a problem but of course I could not run it in Lazarus since the run button/menu entry is disabled.

Check Project Options->Miscellanous->Project Is Runnable. CGI wizard automatically uncheck this because it makes no sense for CGI.

Running on the command line gave a socket error which looks like it is working (perhaps changing the port from 80 to something else fixes this).

I don't remember whether the default is 80 or not, I always set it explicitly via Application.Port.

If it's that simple why is it that hard to get that information. Please, tell me I am stupid and there is a wiki page that I just did not find.

Perhaps it's your turn to contribute to fcl-web wiki article :)

P.S.: If you use Nginx or any other web server whose FastCGI executable must be started manually, you can also debug from IDE

View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Developing-with-fcl-web-tp4038075p4038088.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

Michael Schnell
to Michael Van Canneyt: That depends. It depends on how you set it up. There are 2 options: 1. Use embedded…
Michael Van Canneyt wrote
2. You can run the fastcgi server ...

AFAIK, the fastCGI specification allows for having the WebServer and the CGI communicate via TCP/IP. In this case the CGI is not necessarily started by the WebServer but can be a permanently running executable and even reside on a different machine. Here a normal debugging should be possible as well.

-Michael

Reply by email

Michael Van Canneyt
to Michael Schnell
Michael Schnell wrote 7 lines
On 07/26/2014 02:47 PM, Michael Van Canneyt wrote: > 2. You can run the fastcgi server ... AFAIK, the fastCGI specification allows for having the WebServer and the CGI communicate via TCP/IP. In this case the CGI is not necessarily started by the WebServer but can be a permanently running executable and even reside on a different machine. Here a normal debugging should be possible as well.

Well, yes. Why are you repeating what 2 people already replied ?

Michael.

Reply by email

Reinier Olislagers
to Michael Van Canneyt
Michael Van Canneyt wrote 15 lines
On Mon, 28 Jul 2014, Michael Schnell wrote: > On 07/26/2014 02:47 PM, Michael Van Canneyt wrote: >> 2. You can run the fastcgi server ... > > AFAIK, the fastCGI specification allows for having the WebServer and > the CGI communicate via TCP/IP. In this case the CGI is not > necessarily started by the WebServer but can be a permanently running > executable and even reside on a different machine. Here a normal > debugging should be possible as well. Well, yes. Why are you repeating what 2 people already replied ?

Because he's good at sending but not receiving.

Reply by email

Michael Schnell
to Michael Van Canneyt: Well, yes. Why are you repeating what 2 people already replied ? Michael.
Michael Van Canneyt wrote
Well, yes. Why are you repeating what 2 people already replied ?

???

You did mention TCP/IP via port 10020, but you also stated "if you use mod_fastcgi.so". I tired to offer that this might not only possible with a ".so" (linked object to be started by Apache and hence creating the debugging "attach" problem in question) but also with a stand alone executable, started by the debugger.

-Michael (just trying to be helpful)

Reply by email

Michael Van Canneyt
to Michael Schnell
Michael Schnell wrote 9 lines
On 07/28/2014 05:28 PM, Michael Van Canneyt wrote: > Well, yes. Why are you repeating what 2 people already replied ? ??? You did mention TCP/IP via port 10020, but you also stated "if you use mod_fastcgi.so". I tired to offer that this might not only possible with a ".so" (linked object to be started by Apache and hence creating the debugging "attach" problem in question) but also with a stand alone executable, started by the debugger.

Then IMHO you have not understood how fastcgi works.

Fastcgi always works with a stand-alone executable.

mod_fastcgi.so is not a FPC module, but an apache module that implements FastCGI support for Apache. It has nothing to do with FPC. There is also mod_fcgid.so, which does the same, but which insists on starting the fastcgi binary by itself. The latter is not suitable for debugging the executable.

Michael.

Reply by email