README.txt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. Simple template, example
  2. ================
  3. The simplest template with one template tag in it to be replaced by the
  4. CGI/FCGI/Apache module application when generating the response page
  5. -> ex: {TagName1}
  6. Note, that the only difference between CGI/FCGI and Apache module is in the
  7. main project .lpr file.
  8. =====================
  9. 1. Compiling
  10. 1.a; with FPC
  11. 1.b; with Lazarus
  12. 2. Setup
  13. 2.a; as CGI
  14. 2.b; as Apache module
  15. 2.c; as FCGI
  16. =====================
  17. 1. Compiling:
  18. -------------
  19. We can either use FPC directly, or Lazarus to compile the CGI/FCGI/Apache
  20. module application. The main project .lpr file, as well as the Lazarus .lpi is
  21. in the cgi/fcgi/apache directories.
  22. 1.a; with FPC
  23. -------------
  24. Enter to the directory (cgi/fcgi/apache) that has the .lpr file you wish to
  25. compile, and then execute the command
  26. fpc -Fu../webmodule simpletemplate.lpr
  27. The -Fu parameter shows FPC where to find the web module source code. All
  28. three web applications share the same web module code.
  29. 1.b; with Lazarus
  30. -----------------
  31. It needs the WebLaz Package installed. Open the .lpi file from the chosen
  32. application directory (cgi/fcgi/apache), and then
  33. Run -> Build from the menu.
  34. 2. Setup:
  35. ---------
  36. The application needs read access to the template file(s).
  37. It is best to use full paths with the file names in the web module
  38. (webmodule.pas), because Apache will probably look relative to the / (main
  39. root) directory or main Apache directory and not relative to the application
  40. file location.
  41. ex: ModuleTemplate.FileName := '/full/path/to/template/mytemplate1.html';
  42. 2.a; as CGI
  43. -----------
  44. Usually it works if you put the template (mytemplate1.html) next to the CGI
  45. executable file in the Apache cgi-bin directory. Adjust the file path in the
  46. web module (webmodule.pas) accordingly.
  47. http://<WebServer>/cgi-bin/<CGIExecutableName>/func1call should start the
  48. example if everything is set up properly.
  49. ex: http://127.0.0.1:8080/cgi-bin/simpletemplate.exe/func1call
  50. If the calling URL looks too long, or you want to hide it a little bit more,
  51. you can use a ScriptAlias in the Apache configuration file to make it shorter.
  52. ex: ScriptAlias /mycgi "<path_to_cgi_app>/simpletemplate.exe" in your conf
  53. file will make http://127.0.0.1:8080/mycgi/func1call work the same way.
  54. Note: You need to change the URLs if "cgi-bin" or "simpletemplate.exe"
  55. changes (for example on Linux it is not simpletemplate.exe).
  56. Also, if your server is listening on port 80 instead of 8080, you can leave
  57. the :8080 part from the calling URL.
  58. 2.b; as Apache module
  59. ---------------------
  60. Usually it works if you put the template (mytemplate1.html) into the Apache
  61. main directory (not the DocumentRoot, but the main Apache directory), under
  62. sub-directory "templates" or something similar. Adjust the file path in the
  63. web module (webmodule.pas) accordingly.
  64. http://<WebServer>/<ApacheLocationName>/func1call should start the
  65. example if everything is set up properly.
  66. ex: http://127.0.0.1:8080/myapache/func1call
  67. if in httpd.conf it was set up as:
  68. LoadModule mod_simpletemplate "<path_to_mod>/simpletemplate.dll"
  69. <Location /myapache>
  70. SetHandler mod_simpletemplate
  71. Order allow,deny
  72. Allow from all
  73. </Location>
  74. Note: You need to change the URLs "myapache" or "simpletemplate.dll"
  75. changes. For example on Linux the module can be libsimpletemplate.so and not
  76. simpletemplate.dll
  77. Note: If you recompile an apache module while the module itself is loaded into
  78. the Apache server, the compilation might fail because the file is in use
  79. (Apache modules stay in the memory). So first, you always need to stop the
  80. server before you recompile or before you copy over the new version of the
  81. newly created module.
  82. On Linux, it is enough to simply reload Apache after recompile.
  83. 2.c; as FCGI
  84. ------------
  85. Usually it works if you put the template (mytemplate1.html) next to the FCGI
  86. executable file. Adjust the file path in the web module (webmodule.pas)
  87. accordingly.
  88. http://<WebServer>/<ApacheScriptAliasName>/func1call should start the example
  89. if everything is set up properly.
  90. ex: http://127.0.0.1:8080/myfcgi/func1call
  91. if in the Apache configuration file (ex: httpd.conf) it was set up as:
  92. LoadModule fastcgi_module "<path_to_mod>/mod_fastcgi-2.4.6-AP22.dll"
  93. <IfModule mod_fastcgi.c>
  94. <Directory "<path_to_fcgi_app>">
  95. # Options +ExecCGI <- not needed if ScriptAlias is used below
  96. Order allow,deny
  97. Allow from all
  98. </Directory>
  99. #External FCGI app, has to start manually, Apache will not do it
  100. FastCgiExternalServer "<path_to_fcgi_app>/simpletemplate.exe" -host 127.0.0.1:2015 -idle-timeout 30 -flush
  101. #optionally, to shorten the calling URL and to not display the executable file name (if used, no +ExecCGI is needed above)
  102. ScriptAlias /myfcgi "<path_to_fcgi_app>/simpletemplate.exe"
  103. </IfModule>
  104. Note: You need to change the module name if needed. For example on Linux,
  105. the module is not mod_fastcgi-2.4.6-AP22.dll but mod_fastcgi.so (need to be
  106. compiled from sources found at http://www.fastcgi.com/dist/ ).
  107. The port (2015 in this example) must match the one set in the project main
  108. file (simpletemplate.lpr).
  109. The FCGI application must be running in order for this demo to work (external
  110. FCGI server setup). Do not forget to restart it after changes and
  111. recompilation.
  112. Also, mod_fastcgi is not the same as mod_fcgid that the Apache project is
  113. developing. The latter does not support external FCGI server apps.
  114. There are other ways than external FCGI server apps to handle the FCGI
  115. protocol and both mod_fastcgi and mod_fcgid supports that. However, external
  116. FCGI servers are the best for debugging and development, that is why the
  117. examples do it that way.