Fastcgi on apache » History » Version 5
Wim Dumon, 08/23/2011 11:25 AM
1 | 4 | Peter Mortensen | h1. FastCGI on Apache |
---|---|---|---|
2 | 1 | Koen Deforche | |
3 | h2. Using mod_fastcgi |
||
4 | |||
5 | 4 | Peter Mortensen | 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@. |
6 | 1 | Koen Deforche | |
7 | Next you need to modify the configuation file: |
||
8 | |||
9 | <pre> |
||
10 | <IfModule mod_fastcgi.c> |
||
11 | AddHandler fastcgi-script .wt |
||
12 | FastCgiIpcDir /var/lib/apache2/fastcgi |
||
13 | FastCgiConfig -idle-timeout 100 -maxClassProcesses 1 -initial-env WT_APP_ROOT=/tmp |
||
14 | </IfModule> |
||
15 | </pre> |
||
16 | |||
17 | 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): |
||
18 | |||
19 | <pre> |
||
20 | FastCgiExternalServer /var/www/wt-examples/simplechat/simplechat.wt -host localhost:9091 -idle-timeout 200 |
||
21 | </pre> |
||
22 | |||
23 | 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. |
||
24 | |||
25 | 4 | Peter Mortensen | The only thing left to do is enable CGI execution in your Apache configuration (see below). |
26 | 1 | Koen Deforche | |
27 | h2. Using mod_fcgid |
||
28 | |||
29 | 4 | Peter Mortensen | 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@. |
30 | 1 | Koen Deforche | |
31 | Next you need to modify the configuration file: |
||
32 | |||
33 | <pre> |
||
34 | <IfModule mod_fcgid.c> |
||
35 | AddHandler fcgid-script .wt |
||
36 | SocketPath /var/lib/apache2/fcgid/sock |
||
37 | IdleTimeout -1 |
||
38 | ProcessLifeTime -1 |
||
39 | 2 | Koen Deforche | MaxProcessCount 10 |
40 | DefaultMaxClassProcessCount 10 |
||
41 | 1 | Koen Deforche | DefaultMinClassProcessCount 1 |
42 | </IfModule> |
||
43 | </pre> |
||
44 | |||
45 | and then do this command: |
||
46 | <pre> |
||
47 | chown www-data:www-data /var/run/wt -R |
||
48 | </pre> |
||
49 | |||
50 | 4 | Peter Mortensen | h2. Enabling CGI in Apache |
51 | 1 | Koen Deforche | |
52 | 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): |
||
53 | |||
54 | <pre> |
||
55 | <Directory /var/www/wt/> |
||
56 | #Order Deny,Allow |
||
57 | Allow from all |
||
58 | # Enable CGIs to be executed |
||
59 | Options ExecCGI |
||
60 | </Directory> |
||
61 | </pre> |
||
62 | 4 | Peter Mortensen | Then, we need to create folder /var/run/wt and to give the Apache server write permissions to that directory. |
63 | Next I enable the site and reload Apache: |
||
64 | 1 | Koen Deforche | <pre> |
65 | a2ensite wt |
||
66 | /etc/init.d/apache2 reload |
||
67 | </pre> |
||
68 | 5 | Wim Dumon | |
69 | h2. If it does not work |
||
70 | |||
71 | You may need to create a run directory with the proper permissions: |
||
72 | <pre> |
||
73 | sudo mkdir /var/run/wt |
||
74 | sudo chown www-data:www-data /var/run/wt -R |
||
75 | </pre> |
||
76 | |||
77 | Verify that you have at least two threads configured in /etc/wt/wt_config.xml: |
||
78 | <pre> |
||
79 | <num-threads>2</num-threads> |
||
80 | </pre> |
||
81 | |||
82 | Ensure yourself that your wt application is linked against libwtfcgi instead of libwthttpd. E.g. in your own CMakeLists.txt, write |
||
83 | <pre> |
||
84 | target_link_libraries(hello.wt wt wtfcgi .......) |
||
85 | </pre> |
||
86 | or for the examples included with Wt, set EXAMPLES_CONNECTOR to wtfcgi: |
||
87 | <pre> |
||
88 | cmake -DEXAMPLES_CONNECTOR="wtfcgi" |
||
89 | </pre> |
||
90 | |||
91 | 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. |