Apache module compiling with 0.9.26 lazarus / 1-Linux ---------------------------------------------------------------------- sandeep_c24 · 2009-02-14 02:08 I am trying to write apache module using Lazarus 0.9.26 and I followed the instructions on the page http://wiki.lazarus.freepascal.org/FPC_and_Apache_Modules#Advantages_o f_writing_a_Apache_module_on_Free_Pascal But for some reason the httpd file linked in is for http13 and not httpd22. Has anyone ever managed to get this to work, please help if have. Sandeep ---------------------------------------------------------------------- Vincent Snijders · 2009-02-14 07:36 Did you choose the version using a define? Or is that choice made in your fpc.cfg? ---------------------------------------------------------------------- sandeep_c24 · 2009-02-14 08:52 I didn't change anything in fpc.cfg, it used default settings. Sandeep ---------------------------------------------------------------------- Vincent Snijders · 2009-02-14 19:58 Can you look at the fpc.cfg to make sure you are using the right httpd units dir? ---------------------------------------------------------------------- sandeep_c24 · 2009-02-15 03:08 This is what the fpc.cfg looks like #IFDEF FPCAPACHE_1_13 -Fuc:\lazarus0926\fpc\2.2.2/units/$FPCTARGET/httpd-1.3/ #ELSE #IFDEF FPCAPACHE_2_0 -Fuc:\lazarus0926\fpc\2.2.2/units/$FPCTARGET/httpd-2.0 #ELSE -Fuc:\lazarus0926\fpc\2.2.2/units/$FPCTARGET/httpd-2.2 #ENDIF #ENDIF Could you please tell what I need to change to use 2.2 and what do I need to recompile for this to work. Sandeep ---------------------------------------------------------------------- Vincent Snijders · 2009-02-15 08:55 The directory name is wrong, it does not contain hyphen (-) or dot (.). So it should be: Code: [Select]#IFDEF FPCAPACHE_1_13 -Fuc:\lazarus0926\fpc\2.2.2/units/$FPCTARGET/httpd13 #ELSE #IFDEF FPCAPACHE_2_0 -Fuc:\lazarus0926\fpc\2.2.2/units/$FPCTARGET/httpd20 #ELSE -Fuc:\lazarus0926\fpc\2.2.2/units/$FPCTARGET/httpd22 #ENDIF #ENDIF If that doesn't work, you may need to remove the httpd13 and httpd20 directories, so that the compile cannot find the units in those directories. ---------------------------------------------------------------------- sandeep_c24 · 2009-02-15 10:45 Deleting those folders helped. I can get mod_hello example to work properly. I am now trying a simple apache module created using Lazarus and it just hangs. After debugging I found the app hangs in procedure  GetAWebModule;       if (M=nil) then       begin         M:=MC.Create(Self);<-- This is the line where it hangs         M.Name := '';       end; What should I try now? Sandeep ---------------------------------------------------------------------- Vincent Snijders · 2009-02-15 10:51 No idea. ---------------------------------------------------------------------- sandeep_c24 · 2009-02-15 10:55 Is apache module working with TFPWebModule in any version of FPC? Sandeep ---------------------------------------------------------------------- bobo · 2009-02-16 03:00 No, with 0.9.26 Yes, with the latest SVN for fpc and lazarus they should work with apache 2.2 You have to make sure that you are using the right httpd22 directory in your project and not the httpd13 or httpd20 ones for your compilations. I didn't play with apache modules for a few months, but all bug reports and patches are done now in this area. (0012373, 0012374, 0012375, 0012389, etc.) ---------------------------------------------------------------------- sandeep_c24 · 2009-02-16 10:13 The example on page http://wiki.lazarus.freepascal.org/FPC_and_Apache_Modules#Hello_World_ Module works fine on windows but it doe not work at all on Linux. I can compile it but when I restart apache I get an error about tes_module not in the so. Has anyone been able to get this to work on linux? Regards Sandeep ---------------------------------------------------------------------- bobo · 2009-02-16 21:09 The wiki is not up to date with the latest changes. For example: {$ifdef WINDOWS} exports  test_module name 'test_module'; {$endif} is not correct because it is supported under Linux now. Should be exports test_module name 'test_module'; (note: The module name must be the same as the exports name) In the latest FPC SVN checkout /packages/httpd22/examples/mod_hello.pp contains the correct code. Also, for apache modules using fpApache, fpWeb, lazweb the main program's first uses clause should look like . . . uses {$ifdef unix}   cthreads, {$endif} . . . This is also included in the latest Lazarus SVN so theoretically it should be there when someone creates a new apache module from Lazarus. ---------------------------------------------------------------------- sandeep_c24 · 2009-02-17 07:53 Hi bobo After doing the changes as suggested by you, the apache server now starts. The problem now I have is that the page is not visible when I go to http://localhost/pmod. ____________________________________________________ This is the log in apache error log Heap dump by heaptrc unit 20 memory blocks allocated : 1282/1320 20 memory blocks freed     : 1282/1320 0 unfreed memory blocks : 0 True heap size : 360448 True free heap : 360448 ____________________________________________________ I am using Lazarus 0.9.26. Sandeep ---------------------------------------------------------------------- bobo · 2009-02-17 08:55 I dont think itll work with 0.9.26 , the patches I listed previously are not applied in there. You need to both compile the latest FPC and Lazarus from SVN source. ---------------------------------------------------------------------- sandeep_c24 · 2009-02-17 08:58 Where can I download the latest version for Kubuntu. I am new to linux and Lazarus. I think I should download using SVN so that I can keep things up to date. Is there any tutorial on this? Sandeep ---------------------------------------------------------------------- Leledumbo · 2009-02-18 03:53 QuoteI think I should download using SVN so that I can keep things up to date. Is there any tutorial on this?http://wiki.lazarus.freepascal.org/Installing_Lazarus ---------------------------------------------------------------------- sandeep_c24 · 2009-02-18 07:36 I have successfully downloaded fpc source using svn but I cannot follow what to do from section Installing Free Pascal under Linux/BSD manually. Could someone please give more info. I am trying to install fpc and lazarus using svn snapshots as I need to write apache modules. Sandeep ---------------------------------------------------------------------- sandeep_c24 · 2009-02-19 09:46 I am using FPC and Lazarus from svn and I am still getting following error in apache's error log. This is the log in apache error log Heap dump by heaptrc unit 20 memory blocks allocated : 1282/1320 20 memory blocks freed     : 1282/1320 0 unfreed memory blocks : 0 True heap size : 360448 True free heap : 360448 Is anyone using Apache module successfully? Sandeep ---------------------------------------------------------------------- sandeep_c24 · 2009-02-19 10:04 I made a new Apache module application using Lazarus and it is working now. Before I was trying to compile mod_hello app. The next problem I have is the ARequest parameter does not have any query field values. Is this a know bug? Sandeep ---------------------------------------------------------------------- bobo · 2009-02-19 19:15 Nope, it should work. ARequest.QueryFields stringlist should contain all the query parameters. CGI applications had problems until a few months ago with the ARequest.Contentfields but that was fixed last September so if you have the latest SVN compiled FPC and Lazarus, it should work. How do you pass the query parameters to the apache module (what is the URL you call the apache module with)? ---------------------------------------------------------------------- Leledumbo · 2009-02-20 04:21 QuoteI am using FPC and Lazarus from svn and I am still getting following error in apache's error log.It's not an error, but rather than a report regarding memory usage of the application. It's activated by -gh switch or if used units have HeapTrc in their uses clause. The report shows that no memory leak occurs. ---------------------------------------------------------------------- sandeep_c24 · 2009-02-20 09:36 Hi bobo the url I use is http://localhost/sc/index?page=1 and the code I have is   AResponse.Content := 'Query parameters are '     + ARequest.QueryFields.Text + ' - '     + ARequest.QueryFields.Values['page']; The only thing I see in web page is 'Query parameters are '. Sandeep ---------------------------------------------------------------------- sandeep_c24 · 2009-02-20 22:00 I have had a look at the source and I think the reason no query string is returned is because in following procedure Code: [Select]procedure TApacheRequest.InitFromRequest; Var   I : Integer;   S : String;   begin   // This fills the internal table. We should try   // to get rid of it.   For I:=0 to NoHTTPFields do     begin     S:=GetFieldValue(i);     If (S<>'') then       SetFieldValue(I,S);     end; end; the value of constant NoHTTPFields is 24 and in function Code: [Select]function TApacheRequest.GetFieldValue(Index: Integer): String; request argument is returned for index of 33 Code: [Select]      33 : Result:=StrPas(FRequest^.args); // Query Sandeep ---------------------------------------------------------------------- bobo · 2009-02-21 02:22 Need to check this out. Might be some bug there now. ---------------------------------------------------------------------- bobo · 2009-02-22 01:27 OK, it seems that this was not developed for apache modules yet. And it is not as simple as to just run that loop until higher numbers, the code is not there for that in the GetFieldValue, SetFieldValue. So best if everyone keeps with the CGI applications for now until it is added. ---------------------------------------------------------------------- bobo · 2009-02-22 13:47 Here are some updates attached that should work now for the apache modules. Just overwrite these files in your FPC /packages/fcl-web/src/ folder and recompile both FPC and Lazarus. Or it should work by copying them next to your project files theoretically. Changes: 1. Added: CGI and Apache applications' temporary uploaded files will be deleted after a request is handled /html forms with file upload(s)/ 2. Fixed: Temporary files are not created with a single CRLF in them for html forms where no file was uploaded. 3. Added: Apache applications are now processing and passing the input parameters GET/PUT (QueryFields, ContentFields, uploaded files, etc.). This was only there for CGI applications. 4. THTTPHeader and descendants RemoteAddress property renamed to RemoteAddr for Delphi compatibility 5. Note: For some unknown reason the ap_get_remote_host(FRequest^.Connection, FRequest^.Per_Dir_Config, REMOTE_HOST, Nil) is always crashing for me, therefore this field is not populated at the moment (commented out). This would force a DNS lookup according to the HostnameLookups setting in the Apache configuration. I think that's it. If it works I'll submit these changes into the bug tracking system so it can be further rewieved and integrated into the SVN. ---------------------------------------------------------------------- sandeep_c24 · 2009-02-25 04:51 Hi bobo I tried compiling by putting the file in the folder where my App is but that did not work. I then recompiled FPC and Lazarus but now I am getting QuoteRecompiling fpapache, checksum changed for httpd What should I do next? Sandeep ---------------------------------------------------------------------- bobo · 2009-02-25 06:40 Seems some compilation config problem. Try copying all files from the FPC /packages/fcl-web/src/ directory into your project directory then and replace the files I've attached. ---------------------------------------------------------------------- sandeep_c24 · 2009-02-25 07:39 It was because I had httpd13 and httpd20 in the fpc folders. It works fine after I removed them. Thanks bobo for fixing this issue. It seems to work for now, but I'll write a app using it and if there are any problems I'll report them here. Sandeep