<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>HelpOnInstalling/ApacheOnWin32withFastCgi</title></articleinfo><section><title>Configuring FastCGI on Apache on Windows</title><section><title>(And adding it as a local service)</title><para>Moin in the standard CGI configuration is perfectly fine for small workgroups or internal wiki's.  But, if you want to take your wiki performance to the next level, FastCGI is the way to go.  FastCGI will have a noticeable and dramatic impact on speed, which is particularly noticeable on pages with lots of images.  Among other tricks, FastCGI works by keeping the python process open, thereby reducing the small delay caused by waiting for a python process to open for each request. More info is available on the <ulink url="http://www.fastcgi.com/">FastCGI webpage</ulink>. </para><para>This document borrows from <emphasis><ulink url="https://wiki.hcoop.net/HelpOnInstalling/ApacheOnWin32withFastCgi/HelpOnInstalling/FastCgi#">HelpOnInstalling/FastCgi</ulink></emphasis>; but here I try to provide a concrete example that will give you a working wiki on the Windows platform, detailing <emphasis role="underline">all</emphasis> the files that need to be configured within your moin setup. </para></section><section><title>Prerequisites &amp; Requirements</title><orderedlist numeration="arabic"><listitem><para>You already have working copy of MoinMoin on Windows - <emphasis>(See <ulink url="https://wiki.hcoop.net/HelpOnInstalling/ApacheOnWin32withFastCgi/HelpOnInstalling/ApacheOnWin32#">HelpOnInstalling/ApacheOnWin32</ulink>)</emphasis> </para></listitem><listitem><para>You're running Moin version 1.5.x or later.<emphasis> </emphasis> </para></listitem><listitem><para>Assumes your wiki instance is located at <code>d:\moin\mywiki</code> <emphasis>(You will have to adjust these instructions to your specific set up).</emphasis> </para></listitem><listitem><para>If you run (or anticipate running) multiple wiki's on the same server, you will want to have your wiki-farm configured and working <emphasis><emphasis role="underline">first</emphasis></emphasis>.  <emphasis>(You will make life easier for yourself-- because of how FastCGI works, you will not be able to easily call two .FCG files at the same time (nor will it make sense to) from setting up the WikiFastCGIservice below, etc.  If you are only setting up one wiki, then by all means, proceed... (see also <ulink url="https://wiki.hcoop.net/HelpOnInstalling/ApacheOnWin32withFastCgi/HelpOnConfiguration#">HelpOnConfiguration</ulink> and <ulink url="https://wiki.hcoop.net/HelpOnInstalling/ApacheOnWin32withFastCgi/FarmQuestions#">FarmQuestions</ulink>).</emphasis> </para></listitem></orderedlist><para><emphasis>(See also <ulink url="https://wiki.hcoop.net/HelpOnInstalling/ApacheOnWin32withFastCgi/HelpOnInstalling/FastCgi#">HelpOnInstalling/FastCgi</ulink>)</emphasis> </para></section><section><title>Install FastCGI</title><orderedlist numeration="arabic"><listitem><para>Download the latest compiled mod_fastcgi.dll from <ulink url="http://fastcgi.com/dist/"/> e.g., <code>mod_fastcgi-SNAP-0404142202-AP2.dll</code> </para></listitem><listitem><para>Optionally rename it to <code>mod_fastcgi.dll</code> (if you choose not to rename it, be sure to specify the full name in the <code>LoadModule</code> line on the httpd.conf file). </para></listitem><listitem><para>Copy it into the Apache2\modules folder at <code>c:\Program Files\Apache Software\Apache2\modules\</code>. </para></listitem></orderedlist></section><section><title>FastCGI MoinMoin Configuration</title><orderedlist numeration="arabic"><listitem><para>Copy <code>moin.fcg</code> from <code>d:\Python25\share\moin\server</code> to your instance home, <code>d:\Moin\mywiki</code> </para></listitem><listitem><para>Modify the <code>moin.fcg</code> to match your configuration: </para><orderedlist numeration="lowerroman"><listitem><para>Change the first-line shebang statement to point to your python installation. This would be exactly has your old working <code>moin.cgi</code> file: </para><screen><![CDATA[ #! d:/Python25/python]]></screen></listitem><listitem><para>change the <code>sys.path.insert</code> like to point to your wikiconfig.py file (again, just like in your old working <code>moin.cgi</code> file). If you're using a farm, point instead to your farmconfig.py file: </para><screen><![CDATA[sys.path.insert(0, r'd:\moin\mywiki\wikiconfig.py')]]></screen></listitem><listitem><para>The last lines of the moin.fcg file will be similar to below.  For Windows, we need to specify a port number. You can select other port number other than <code>9001</code>, but it should match the one in <code>httpd.conf</code> (see next section below).  (<emphasis role="underline"><emphasis role="strong">note:</emphasis></emphasis> in case your browser window wraps the below example, the <code>fcg = thfcgi.FCGI</code> is all one line, and <code>fcg.run()</code> is on it's own separate line). </para><screen><![CDATA[if __name__ == '__main__':
    fcg = thfcgi.FCGI(handle_request, port=9001, max_requests=max_requests, backlog=backlog, max_threads=max_threads)
    fcg.run()]]></screen></listitem></orderedlist></listitem></orderedlist></section><section><title>httpd.conf Configuration</title><para>Open your Apache config file (<code>c:\Program Files\Apache Software\Apache2\conf\</code>), and add the following directives: </para><orderedlist numeration="arabic"><listitem><para>Scroll down to the LoadModule section and add mod_fastcgi.dll, like in the example below (if you didn't rename your file, you'll need to exactly to match your file name): </para><screen><![CDATA[LoadModule fastcgi_module modules/mod_fastcgi.dll]]></screen></listitem><listitem><para>Scroll down to the AddHandler section and add the following: </para><screen><![CDATA[AddHandler fastcgi-script .fcg]]></screen></listitem><listitem><para>Modify your ScriptAlias line to point to your <code>moin.fcg</code> file (fas we configured in the section above). There are two options here; if you are running a single wiki, use <code>i</code>. If you have a wiki farm, use <code>ii</code>: </para><orderedlist numeration="lowerroman"><listitem><para>Example if you're running a single wiki: </para><screen><![CDATA[ScriptAlias /mywiki    "d:/Moin/mywiki/moin.fcg"]]></screen></listitem><listitem><para>Example if you're running multiple wiki's (i.e. a wiki farm): </para><screen><![CDATA[ScriptAlias /mywiki     "d:/Moin/moin.fcg"
ScriptAlias /yourwiki   "d:/Moin/moin.fcg"
ScriptAlias /theirwiki  "d:/Moin/moin.fcg"]]></screen></listitem></orderedlist></listitem><listitem><para>Register the <code>moin.fcg</code> as an external server. This needs to match the port we specified in <code>moin.fcg</code> in the steps above (if you changed the port number). Make sure the path to <code>moin.fcg</code> points to the correct location. We'll also specify the loopback IP, instead of the interface IP, so that it will work even if the computer's IP address changes. </para><screen><![CDATA[FastCgiExternalServer d:/Moin/mywiki/moin.fcg -host 127.0.0.1:9001]]></screen></listitem></orderedlist><para>When finished, you should have something similar to this at the tail of your httpd.conf file: </para><screen><![CDATA[### point to the python wiki htdocs:
Alias       /wiki/    "D:/Python25/share/moin/htdocs/"
### Your ScriptAlias(es) need to point to your .fcg files:
ScriptAlias /mywiki    "D:/moin/moin.fcg"
ScriptAlias /yourwiki   "D:/moin/moin.fcg"
### Setting the external server:
FastCgiExternalServer d:/Moin/moin.fcg -host 127.0.0.1:9001]]></screen><para>Move your old <code>moin.cgi</code> elsewhere to ensure that it's not being called. </para><para>You're done!  Now it's time to test. </para><para>Open a commandline window (Start &gt; Run... &gt; type <code>cmd</code>), navigate to your <code>moin.fcg</code> location, and type the following command (substituting your python path, as necessary). Leave the window open while you test (closing it will quit the python process). </para><screen><![CDATA[d:\python25\python moin.fcg]]></screen><para>If all went well (and you marveled at how much faster moin is now), you can now proceed to the next section to register moin.fcg as a local service. This ensures that moin will come up across restarts. </para><!--rule (<hr>) is not applicable to DocBook--></section></section><section><title>Register moin.fcg as a local service</title><para>We're now going to create a new service that automatically starts our moin.fcg after reboots. </para><orderedlist numeration="arabic"><listitem><para>Download &amp; install the <ulink url="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd">MS Windows 2003 Resource Kit</ulink>. (of course, you already have the Resource Kit installed, since you're using RoboCopy to back up your wiki, right?! See <ulink url="https://wiki.hcoop.net/HelpOnInstalling/ApacheOnWin32withFastCgi/HelpOnInstalling/Win32MoinEasyBackup#">HelpOnInstalling/Win32MoinEasyBackup</ulink>).  We need two commands from the Resource Kit, <code>srvany.exe</code> and <code>instsrv.exe</code>. For convenience sake, you can optionally move these to some place more convenient (you'll have to navigate to them via the commandline). </para></listitem><listitem><para>From the commandline (Start &gt; Run... &gt; type <code>cmd</code>), navigate to your Resource Kit folder and type the following to create a new service, which we'll name <code>WikiFastCGIservice.</code> You can use a different name, if you prefer. </para><screen><![CDATA[INSTSRV WikiFastCGIservice C:\Windows\system\srvany.exe]]></screen></listitem><listitem><para>Now we have just created the service, we have to configure it.  Run <code>regedit.exe</code> (Start &gt; Run... &gt; type <code>regedit</code>): </para><orderedlist numeration="lowerroman"><listitem><para>Under <code>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\</code>, create a new key (right-click &gt; New &gt; Key) called <code>WikiFastCGIservice</code>. </para></listitem><listitem><para>Under the <code>WikiFastCGIservice</code> you created above, create a new key (right-click &gt; New &gt; Key) named <code>Parameters</code> </para></listitem><listitem><para>Within the Parameters key, create a new string value (right-click &gt; New &gt; String Value) named <code>Application</code> (key value will be listed as REG_SZ type). Double-click your value and specify the path of application: </para><screen><![CDATA[d:\Python25\python.exe]]></screen></listitem><listitem><para>Within the Parameters key: perform the same steps above, this time creating an <code>AppParameters</code> value and specify a parameter: </para><screen><![CDATA[d:\Moin\mywiki\moin.fcg]]></screen></listitem><listitem><para>Within the Parameters key: perform the same steps above, this time creating an <code>AppDirectory</code> value and specify the current directory: </para><screen><![CDATA[d:\Moin\mywiki]]></screen></listitem></orderedlist></listitem><listitem><para>Now configure it via the Services applet (Start &gt; Settings &gt; Control Panels &gt; Administrative Tools &gt; Services), such as automatic start. </para></listitem></orderedlist><para>You're finished! </para><itemizedlist><listitem override="none"><para><inlinemediaobject><imageobject><imagedata depth="16" fileref="https://wiki.hcoop.net/moin_static1911/moniker_bt/img/attention.png" width="16"/></imageobject><textobject><phrase>&lt;!&gt;</phrase></textobject></inlinemediaobject> <emphasis role="underline"><emphasis role="strong">Note</emphasis></emphasis>: For now on, whenever you make changes to to your wikiconfig.py/farmconfig.py, you will need to restart <emphasis role="strong"><code>WikiFastCGIservice</code></emphasis> via the Services applet (Start &gt; Settings &gt; Control Panels &gt; Administrative Tools &gt; Services) apply the changes. </para></listitem></itemizedlist></section></article>