Project

General

Profile

Fastcgi on apache » History » Revision 5

Revision 4 (Peter Mortensen, 04/15/2011 10:27 PM) → Revision 5/6 (Wim Dumon, 08/23/2011 11:25 AM)

h1. FastCGI on Apache 

 h2. Using mod_fastcgi 

 You'll need to enable mod_fastcgi first for Apache. In most cases, this is done by linking the module's configuration file @fastcgi.conf@ from @mods-available@ to @mods-enabled@ (this can be done by running @a2enmod@. 

 Next you need to modify the configuation file: 

 <pre> 
 <IfModule mod_fastcgi.c> 
   AddHandler fastcgi-script .wt 
   FastCgiIpcDir /var/lib/apache2/fastcgi 
   FastCgiConfig -idle-timeout 100 -maxClassProcesses 1 -initial-env WT_APP_ROOT=/tmp 
 </IfModule> 
 </pre> 

 This will automatically start any file ending with @.wt@ as a FastCGI executable. You can also use "external CGIs", which allow you to control in more detail how a single application gets started (and restarted): 

 <pre> 
   FastCgiExternalServer /var/www/wt-examples/simplechat/simplechat.wt -host localhost:9091 -idle-timeout 200 
 </pre> 

 For this latter deployment option, you need to use the FastCGI utility @cgi-fcgi@ to run the Wt application independent of the web server. When a request for the application is received by the web server, it is forwarded to your FastCGI application using the FastCGI protocol over the given TCP connection. 

 The only thing left to do is enable CGI execution in your Apache configuration (see below). 

 h2. Using mod_fcgid 

 You'll need to enable mod_fcgid first for Apache. In most cases, this is done by linking the module's configuration file @fcgid.conf@ from @mods-available@ to @mods-enabled@ (this can be done by running @a2enmod@. 

 Next you need to modify the configuration file: 

 <pre> 
 <IfModule mod_fcgid.c> 
   AddHandler fcgid-script .wt 
   SocketPath /var/lib/apache2/fcgid/sock 
   IdleTimeout -1 
   ProcessLifeTime -1 
   MaxProcessCount 10 
   DefaultMaxClassProcessCount 10 
   DefaultMinClassProcessCount 1 
 </IfModule> 
 </pre> 

 and then do this command: 
 <pre> 
     chown www-data:www-data /var/run/wt -R 
 </pre> 

 h2. Enabling CGI in Apache 

 Next, we create a new "site" configuration file for Wt applications: @/etc/apache2/sites-available/wt@ which we will install in @/var/www/wt@ (this must be a directory within your docroot): 

 <pre> 
 <Directory /var/www/wt/> 
   #Order Deny,Allow 
   Allow from all 
   # Enable CGIs to be executed  
   Options ExecCGI 
 </Directory> 
 </pre> 
 Then, we need to create folder /var/run/wt and to give the Apache server write permissions to that directory. 
 Next I enable the site and reload Apache: 
 <pre> 
     a2ensite wt 
     /etc/init.d/apache2 reload 
 </pre> 

 h2. If it does not work 

 You may need to create a run directory with the proper permissions: 
 <pre> 
 sudo mkdir /var/run/wt 
 sudo chown www-data:www-data /var/run/wt -R 
 </pre> 

 Verify that you have at least two threads configured in /etc/wt/wt_config.xml: 
 <pre> 
 <num-threads>2</num-threads> 
 </pre> 

 Ensure yourself that your wt application is linked against libwtfcgi instead of libwthttpd. E.g. in your own CMakeLists.txt, write 
 <pre> 
 target_link_libraries(hello.wt wt wtfcgi .......) 
 </pre> 
 or for the examples included with Wt, set EXAMPLES_CONNECTOR to wtfcgi: 
 <pre> 
 cmake -DEXAMPLES_CONNECTOR="wtfcgi" 
 </pre> 

 Look for errors in your apache error log. Especially if you see wt complaining about 'stat' and 'docroot not being set', this means that your executable is linked to wthttpd instead of wtfastcgi; in this case you    need to fix your linker options first.