README.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. Hello world example
  2. ===================
  3. The simplest "Hello World" example using fcl-web (fpweb) that uses a web action
  4. called "func1call" in the web module to generate the response page.
  5. Note that the only difference between CGI/FCGI and Apache module is in the
  6. main project .lpr file and the web server (Apache) configuration.
  7. =====================
  8. 1. Compiling
  9. 1.a; with FPC
  10. 1.b; with Lazarus
  11. 2. Setup
  12. 2.a; as CGI
  13. 2.b; as Apache module
  14. 2.c; as FCGI
  15. =====================
  16. 1. Compiling:
  17. -------------
  18. We can either use FPC directly, or Lazarus to compile the CGI/FCGI/Apache
  19. module application. The main project .lpr file, as well as the Lazarus .lpi is
  20. in the cgi/fcgi/apache directories.
  21. 1.a; with FPC
  22. -------------
  23. Go to the directory (cgi/fcgi/apache) that has the .lpr file you wish to
  24. compile, and then execute the command
  25. fpc -Fu../webmodule helloworld.lpr
  26. The -Fu parameter shows FPC where to find the web module source code. All
  27. three web applications share the same web module code.
  28. 1.b; with Lazarus
  29. -----------------
  30. It needs the WebLaz Package installed. Open the .lpi file from the choosen
  31. application directory (cgi/fcgi/apache), and then
  32. Run -> Build from the menu.
  33. 2. Setup:
  34. ---------
  35. 2.a; as CGI
  36. -----------
  37. http://<WebServer>/cgi-bin/<CGIExecutableName>/func1call should start the
  38. example if everything is set up properly.
  39. ex: http://127.0.0.1:8080/cgi-bin/helloworld.exe/func1call
  40. Note: You need to change the URL if "cgi-bin" or "helloworld.exe" changes
  41. (for example on Linux it is not helloworld.exe).
  42. Also, if your server is listening on port 80 instead of 8080, you can leave
  43. the :8080 part from the calling URL.
  44. 2.b; as Apache module
  45. ---------------------
  46. http://<WebServer>/<ApacheLocationName>/func1call should start the
  47. example if everything is set up properly.
  48. ex: http://127.0.0.1:8080/myapache/func1call
  49. Example Apache configuration file (e.g. httpd.conf) snippet for this:
  50. LoadModule mod_helloworld "<path_to_mod>/helloworld.dll"
  51. <Location /myapache>
  52. SetHandler mod_helloworld
  53. Order allow,deny
  54. Allow from all
  55. </Location>
  56. Note: You need to change the URL if "myapache" changes.
  57. Also, for example on Linux the module can be libhelloworld.so and not
  58. helloworld.dll
  59. Note: If you recompile an apache module while the module itself is loaded into
  60. the Apache server, the compilation might fail because the file is in use
  61. (Apache modules stay in the memory). So first, you always need to stop the
  62. server before you recompile or before you copy over the new version of the
  63. newly created module.
  64. On Linux, it is enough to simply reload Apache after recompile.
  65. 2.c; as FCGI
  66. ------------
  67. http://<WebServer>/<ApacheScriptAliasName>/func1call should start the example
  68. if everything is set up properly.
  69. ex: http://127.0.0.1:8080/myfcgi/func1call
  70. Example Apache configuration file (e.g. httpd.conf) snippet for this:
  71. LoadModule fastcgi_module "<path_to_mod>/mod_fastcgi-2.4.6-AP22.dll"
  72. <IfModule mod_fastcgi.c>
  73. <Directory "<path_to_fcgi_app>">
  74. # Options +ExecCGI <- not needed if ScriptAlias is used below
  75. Order allow,deny
  76. Allow from all
  77. </Directory>
  78. #External FCGI app, has to start manually, Apache will not do it
  79. FastCgiExternalServer "<path_to_fcgi_app>/helloworld.exe" -host 127.0.0.1:2015 -idle-timeout 30 -flush
  80. #optionally, to shorten the calling URL and to not display the executable file name (if used, no +ExecCGI is needed above)
  81. ScriptAlias /myfcgi "<path_to_fcgi_app>/helloworld.exe"
  82. </IfModule>
  83. Note: You need to change the module name if needed. For example on Linux,
  84. the module is not mod_fastcgi-2.4.6-AP22.dll but mod_fastcgi.so (need to be
  85. compiled from sources found at http://www.fastcgi.com/dist/ ).
  86. The port (2015 in this example) must match the one set in the project main
  87. file (helloworld.lpr).
  88. The FCGI application must be running in order for this demo to work (external
  89. FCGI server setup). Do not forget to restart it after changes and
  90. recompilation.
  91. Also, mod_fastcgi is not the same as mod_fcgid that the Apache project is
  92. developing. The latter does not support external FCGI server apps.
  93. There are other ways than external FCGI server apps to handle the FCGI
  94. protocol and both mod_fastcgi and mod_fcgid supports that. However, external
  95. FCGI servers are the best for debugging and development, that is why the
  96. examples do it that way.