Recent

Author Topic: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux  (Read 126169 times)

bobo

  • Full Member
  • ***
  • Posts: 171
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #15 on: November 22, 2012, 09:34:19 am »
Quote
"so this version might not work with Apache 2.4.1 - does anyone know of a verison that does or have I missed something?"

mod_fastcgi does not seem to support Apache 2.4.X , the maintenance is totally stopped on the project it seems.
However, Apache 2.4.X has a new way to do the same functionality now, to do external FCGI server (FastCgiExternalServer) via the new mod_proxy_fcgi module.
I will update the top post once it is figured out how to make it work with fpc/lazarus , and the SVN is updated for fpc as needed to support it. Most probably this new way will be the preferred FCGI external server functionality instead of the old third party mod_fastcgi .

mod_fcgid still works as before, so we still have a perfectly working FCGI way with the latest Apache.
Both mod_fcgid and mod_proxy_fcgi are included in Apache from 2.3.X .

BTW, mod_fcgid is not for real time debugging (unless you are using log files) because in this case Apache loads the FCGI application at startup so there is no way to use a debugger like with the mod_fastcgi method (or with the new mod_proxy_fcgi module).
The  two latter you need to start the FCGI app yourself, hence you can use a debugger to execute them.
Compared to the debugging benefits of the two latter ones, mod_fcgid instead might be a good way for live web servers though, because Apache can start the FCGI app instances as needed, automatically.

Quote
"The bit I struggled with was that the demos have the listening "port" set to 2015 in the application source (the lpr file) - once you comment this out it seems to work fine with this setup - both applications are launched the first time they are called from the browser and remain in memory for each subsequent request."
The port is only used for the mod_fastcgi  FastCgiExternalServer mode (and the new Apache 2.3.X+ mod_proxy_fcgi module) . All other modes do not need that line because they are not using a port to listen on.
« Last Edit: November 22, 2012, 09:53:55 am by bobo »

GiovanniF

  • New Member
  • *
  • Posts: 25
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #16 on: March 07, 2014, 02:26:54 pm »
One simple question:

Using this method:

AResponse.Contents.LoadFromFile('aaa.html');

HOW do I incluse a image into my 'aaa.html' like

<img src="someimage.jpg"> ?

Thanks in advance.

Rgds

GiovanniF

RalphMuc

  • Newbie
  • Posts: 5
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #17 on: March 31, 2014, 07:35:34 pm »
Hi there

thanks for the docu. Silvio's FastCGI Sample works fine.
Do you know how to pass environment Vars to fastcgi ?


Code: [Select]
procedure TMyAction.Get;
begin

 for I := 1 to ParamCount do
   WriteLn('Param ' + inttostr(I)  +  ': ' + ParamStr(I)); 

 WriteLn( 'myREMOTE_ADDR: ' + GetEnvironmentVariable('myREMOTE_ADDR') );
 WriteLn( 'BROOK_CLT_ENV_HTTP_USER_AGENT: ' + GetEnvironmentVariable(BROOK_CLT_ENV_HTTP_USER_AGENT) );
 WriteLn( 'BROOK_SRV_ENV_REMOTE_ADDR: ' + GetEnvironmentVariable(BROOK_SRV_ENV_REMOTE_ADDR) );
 WriteLn( 'BROOK_SRV_ENV_X_FORWARDED_FOR: ' + GetEnvironmentVariable(BROOK_SRV_ENV_X_FORWARDED_FOR) );

end;     

Solved ...
rgds
Ralph
« Last Edit: May 08, 2014, 11:01:42 pm by RalphMuc »

RalphMuc

  • Newbie
  • Posts: 5
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #18 on: May 08, 2014, 11:04:43 pm »
Hi,

the FastCGI sample source code is here : https://github.com/rbmuc/EasyBBS

Ralph

RalphMuc

  • Newbie
  • Posts: 5
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #19 on: May 10, 2014, 06:28:45 pm »
Hi,

i build a installable version of Apache 2.4.9 x86  ( with openssl 1.0.1g and FastCGI ) support.
download https://bergertime.eu/download/httpd-2.4.9-win32-x86-openssl-1.0.1g.exe
docu_en https://bergertime.eu/download/apache_fcgi_en.pdf
docu_de https://bergertime.eu/download/apache_fcgi.pdf

Ralph


cahaya

  • New member
  • *
  • Posts: 8
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #20 on: December 12, 2014, 06:41:57 pm »
Hi all,

I just check mod_proxy_fcgi, it work for lazarus with minor bugs(don't know bug or not).
Here my steps :

1. install apache 2.4 (just copy in windows)
2. enable LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so and
    LoadModule proxy_module modules/mod_proxy.so in httpd.conf.
    You can find file httpd.conf in directory conf.
3. add a new line ProxyPass /fcgi-bin/ fcgi://localhost:9000/ in httpd.conf
    /fcgi-bin/ is a directory I put under htdocs, you can put anywhere as long
    as you set permission.
4. add ScriptAlias /fcgi-bin/ "${SRVROOT}/htdocs/fcgi-bin/" under
    alias_module section.
5. add permission
    <Directory "${SRVROOT}/htdocs/fcgi-bin">
    AllowOverride None
    Options None
    Require all granted
   </Directory>

run your program fcgi. Don't forget to add Application.port := 9000;
uses
  fpFCGI, Main;

begin
  Application.Title:='FpCgi';
  Application.Initialize;
  Application.port := 9000;
  Application.Run;
end.
Please notice unit fpFCGI not fpCGI.

You can not use actio, something like /fcgi-bin/helloword.exe/testaction. In cgi action testaction is recognized by both. But in proxy, it seem apache do not compatible with that feature.

chain_reaction

  • New Member
  • *
  • Posts: 22
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #21 on: November 06, 2015, 05:22:12 am »
Hello everyone, just to confirm that fp-cgi also works perfectly on lighttpd.

DarkEagle

  • Newbie
  • Posts: 1
    • แรนเถื่อน
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #22 on: May 28, 2016, 07:34:55 pm »
i'm finding on many web , so this thread can help me. thank you very much  ;D

egsuh

  • Hero Member
  • *****
  • Posts: 1266
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #23 on: March 24, 2017, 06:47:58 am »
Hello,

I've done a few web projects successfully with Delphi on IIS, both CGI and ISAPI.
I found Lazarus recently, and checking feasibility of web application with Lazarus.
I found that fpweb in Lazarus supports CGI and FastCGI. I've tested them on IIS, and found CGI works fine, but FastCGI doesn't work as expected.
I tried to run it on IIS7 (Windows 7) like as follows:

   http://localhost/fcgi/fcgiproject2.exe


but the response is:

    The application encountered the following error:
    Error: Could not determine HTTP module for request "fcgi"
    Stack trace:
    $0000000100036793
    $000000010003685B
    $0000000100036522
    $0000000100036D8F
    $0000000100035FEF
    $000000010003715F
    $0000000100038365
    $0000000100001847 line 16 of fcgiproject2.lpr
     ......................

Interesting point is that "fcgi" is just a folder name, as the executable file path is  c:\inetpub\wwwroot\fcgi\fcgiproject2.exe.  As "c:\inetpub\wwwroot" is the home directory for localhost, specifying "localhost/fcgi" works fine for other types of files. 

I have tested Apache server too, but the results are the same. I think there are some issue related with pathinfo of other thinks as fcgi is not read as a folder name.

If any of you have solved the same problem, please let me know. I would really appreciate.

Regards,


mobilevil

  • Jr. Member
  • **
  • Posts: 69
    • http://www.kachun.com
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #24 on: August 16, 2017, 05:17:01 am »
hello,
edit: I thought 1.8 RC4 was broken but I was wrong. with 1.8 RC4, the FPC version is updated to 3.0.4 RC1, in which the fp-web package is updated to support routing.
to enable legacy routing to fix my stupid hello world FCGI applicaiton,  add this to the main program.

Application.LegacyRouting:=true;


just to report that mod_fastcgi from mod_fastcgi-2.4.7.1-2.4.x-x64-vc14.zip, https://www.apachehaus.net/modules/mod_fastcgi/ is working for me, default and custom actions are fine.

both FastCgiServer and FastCgiExternalServer are working, but note that only the external config need the port setup line in the FCGI project
  Application.Port:=9999; // For example     

The FastCgiExternalServer mode is really good for debugging, and under windows the FCGI exe won't be locked by anyone so you can kill it anytime you like. You can debug, modify the code and build as you wish.

I am using apache 2.4 64 bit, httpd-2.4.27-x64-vc14.zip

this is my apache config

LoadModule fastcgi_module "modules/mod_fastcgi.so"
<IfModule mod_fastcgi.c>
  <Directory "C:/checkout/testfcgi/lib/x86_64-win64">
    #this two is for 2.2 only
    #Order allow,deny
    #Allow from all
    #this line is needed for 2.4
    Require all granted
  </Directory>
  #regular fast cgi, CGI exe itself is always loaded by apache, non-debuggable, for production
#  FastCgiServer "C:/checkout/testfcgi/lib/x86_64-win64/testfcgi.exe" -idle-timeout 30

  #external server fast cgi, debuggable, have to start the cgi program manually
  FastCgiExternalServer "C:/checkout/testfcgi/lib/x86_64-win64/testfcgi.exe" -host 127.0.0.1:9999 -idle-timeout 30 -flush
  ScriptAlias /myfcgi "C:/checkout/testfcgi/lib/x86_64-win64/testfcgi.exe"
</IfModule>
--------------------------------------
and here's my FCGI prrogram's main
begin
  Application.Title:='fcgiproject1';
  { Uncomment the port setting here if you want to run the
    FastCGI application stand-alone (e.g. for NGINX) }
  Application.Port:=9999; // For example
  Application.Initialize;
  Application.Run;
end.     


procedure TFPWebModule1.helloRequest(Sender: TObject; ARequest: TRequest;
  AResponse: TResponse; Var Handled: Boolean);
var
  i:integer;
begin
  AResponse.contents.Add(datetimetostr(now)+' Hello world fast cgi with external server!<br>');
  AResponse.contents.Add(ARequest.URL+'<br>');
  for i:=0 to ARequest.FieldCount-1 do
  begin
    AResponse.contents.Add(ARequest.FieldNames + ' ' + ARequest.FieldValues+sLineBreak);
  end;
  Handled:=true;
end;

procedure TFPWebModule1.TFPWebAction0Request(Sender: TObject;
  ARequest: TRequest; AResponse: TResponse; Var Handled: Boolean);
var
  i:integer;
begin
  AResponse.contents.Add(datetimetostr(now)+' default action with external server!<br>');
  AResponse.contents.Add(ARequest.URL+'<br>');
  for i:=0 to ARequest.FieldCount-1 do
  begin
    AResponse.contents.Add(ARequest.FieldNames + ' ' + ARequest.FieldValues+sLineBreak);
  end;
  Handled:=true;
end;

initialization
  RegisterHTTPModule('TFPWebModule1', TFPWebModule1);
end.
             


« Last Edit: December 12, 2020, 03:29:10 pm by mobilevil »

sfischer

  • New Member
  • *
  • Posts: 37
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #25 on: August 05, 2018, 04:28:42 pm »
Hi,
I try to get example program fcl-web/examples/helloworld running with lighttpd as webserver on raspian.
an excerpt of my /etc/lighttpd/lighttpd.conf looks like:

fastcgi.debug = 1
fastcgi.server = (
    "/helloworld" => (
      "helloworld.fcgi.handler" => (
        "socket" => "/tmp/helloworld.socket",
        "check-local" => "disable",
# "host" => "127.0.0.1",
# "port" => "2015",
        "bin-path" => "/var/lib/BASIS/pump/www/cgi-bin/helloworld",
        "max-procs" => 1
      )
    )
)

can someone supply a small manual, ho to get this working
thanks,
SF

matthius

  • Full Member
  • ***
  • Posts: 155
  • Creating VRAD...
    • LIBERLOG - Développement rapide
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #26 on: December 10, 2020, 04:35:07 pm »
I want to test my fast CGI.
I have created a VirtualHost to use 2015 port.

I get always this error for a long time, on Debian Buster and Ubuntu 20 :

Exception at 000000000048DE0B: EFPWebError:
Failed to bind to port 2015. Socket Error: 98.

The config is here :

<VirtualHost *:2015>
<Directory /var/www/cgi-bin>
Options All
AllowOverride All
Require all granted
Options +ExecCGI +FollowSymLinks

   SetHandler fcgid-script
   AddHandler fcgid-script .cgi
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

Listen 2015

ScriptAlias /cgi-bin "/var/www/cgi-bin"
« Last Edit: December 10, 2020, 04:40:23 pm by matthius »
M. GIROUX
13 rue Tanguy PRIGENT
35000 RENNES - France
(33)(0)2 23 46 06 54
http://liberlog.fr

mobilevil

  • Jr. Member
  • **
  • Posts: 69
    • http://www.kachun.com
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #27 on: December 11, 2020, 04:44:09 pm »
quick google and a random guess
https://stackoverflow.com/questions/17780291/python-socket-error-errno-98-address-already-in-use

address is already in use, since it is not a well known port, I guess it is not something else that is using it. I GUESS you have a looping config file so that apache is trying to bind the same port twice. or something similar

matthius

  • Full Member
  • ***
  • Posts: 155
  • Creating VRAD...
    • LIBERLOG - Développement rapide
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #28 on: December 11, 2020, 05:29:14 pm »
After and only after starting a fcgi script i get this :
netstat | grep 9000
tcp6       0      0 127.0.0.1:9000          127.0.0.1:58058         TIME_WAIT
M. GIROUX
13 rue Tanguy PRIGENT
35000 RENNES - France
(33)(0)2 23 46 06 54
http://liberlog.fr

mobilevil

  • Jr. Member
  • **
  • Posts: 69
    • http://www.kachun.com
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #29 on: December 12, 2020, 03:06:50 pm »
OK I was wrong. The bind error came from FCGI, not APACHE.
Apache should use it's own port, and FCGI use another.
e.g. Apache should use the default port 80, and FCGI's port is defined in both FCGI's main, and apache's config

see my post a few post above dated 2017.
look for FastCgiExternalServer and application.port

 

TinyPortal © 2005-2018