Catalyst+Apache+FastCGI on MS Windows

If you are about to run a Catalyst application as FastCGI on a Microsoft Windows box you can either use Microsoft IIS (it is an option just for 2003, Vista, 2008 and above) or you can use any FastCGI capable 3rd party web server - in the latter case using Apache/Win32 is an alternative.

This article describes configuration valid just for Apache 2.2. The binaries of some Apache modules attached to this page are compiled for Win32 and requires Apache 2.2.9+.

First you need Perl + Catalyst framework

Important note: the configuration described in this article was tested with Strawberry Perl for Windows.

Quick steps:

set PERL_MM_USE_DEFAULT=1
perl -MCPAN -e "notest('install', 'HTTP::Server::Simple', 'WWW::Mechanize');"
cpan Catalyst::Runtime Catalyst::Devel FCGI
  • Note: the installation of HTTP::Server::Simple and WWW::Mechanize on Win32 needs to be forced without running tests.

  • Note: Do not forget to install FCGI module as it not a standard dependency of Catalyst::Runtime or Catalyst::Devel.

  • Let us assume that we have a perl + catalyst installed in: c:\strawberry\

Install your Catalyst application

Put your Catalyst application for example into directory: c:\inetpub\WebApp\

Or you can create a new empty catalyst application from command prompt:

C:\Inetpub>catalyst WebApp

At this point you can also consider running:

C:\Inetpub\WebApp>perl Makefile.PL
...
C:\Inetpub\WebApp>dmake installdeps
...

Very important: c:\inetpub\WebApp\script\webapp_fastcgi.pl has to have the following shebang line:

#!c:\strawberry\perl\bin\perl.exe -w

Install Apache for Windows

As mentioned above we need to install Apache 2.2.9 or higher. The easiest way is to download and install precompiled Apache binary:

Let us assume that we have installed Apache for Win32 into: C:\Program Files\Apache Software Foundation\Apache2.2\

Install Apache FastCGI module

FastCGI support is not a part of standard Apache webserver distribution. Currently there exist two Apache modules implementing FastCGI: mod_fastcgi and mod_fcgid.

For running Catalyst application as FastCGI on Apache/Win32 you have to choose mod_fastcgi (the author of this article did not manage after many tries to run catalyst app via mod_fcgid).

It seems to be necessary to use currently latest snapshot version 0811090952 containing important fixes for Win32 (current stable version 2.4.6 does not work well). The easiest way is to use the binary attached to this article:

To configure Apache web server to run your Catalyst application via FastCGI add at the end of your default C:\Program Files\Apache Software Foundation\Apache2.2\modules\httpd.conf the following:

LoadModule fastcgi_module modules/mod_fastcgi.so

#the following option is necessary if the perl interpret needs to load
#some DLL libraries located somewhere in PATH on your system
FastCgiConfig -initial-env PATH

#setup your virtual host
Listen localhost:4000
<VirtualHost localhost:4000>

#it is not clever to publish the whole .../WebApp/root - do it rather this way
Alias /favicon.ico c:/inetpub/WebApp/root/favicon.ico
Alias /static/ c:/inetpub/WebApp/root/static/
Alias / c:/inetpub/WebApp/script/webapp_fastcgi.pl/

<Directory c:/inetpub/WebApp/script>
Options ExecCGI
SetHandler fastcgi-script
</Directory>

<Location />
Order allow,deny
Allow from all
</Location>

</VirtualHost>

Now you can point your browser to: http://localhost:4000/

If the application did not work you can look into Apache logs (C:\Program Files\Apache Software Foundation\Apache2.2\logs\) for error details.

Important note: PAR distribution of a catalyst application cannot be run via mod_fastcgi on Apache/Win32.

Install Apache SSPI Auth module (integrated authentication)

This module is not necessary for running Catalyst application so this chapter is slightly off topic. However if want to use in your catalyst app so called "integrated authentication" (popular in corporate intranet applications in MS Windows world) you will find this module handy.

We are talking about mod_auth_sspi module. The easiest way is to use the binary attached to this article:

  • Download link: mod_auth_sspi-1.0.4-Win32.zip (binary)

  • Note: it is Win32/x86 binary; works just with Apache 2.2.9+

  • To instal simply extract the file mod_auth_sspi.so into C:\Program Files\Apache Software Foundation\Apache2.2\modules\

  • Module homepage

To configure Apache web server to run your Catalyst application with SSPI Auth support you have to add at the end of your default C:\Program Files\Apache Software Foundation\Apache2.2\modules\httpd.conf the following (it includes also necessary mod_fastcgi configuration):

LoadModule fastcgi_module modules/mod_fastcgi.so
FastCgiConfig -initial-env PATH

LoadModule sspi_auth_module modules/mod_auth_sspi.so

Listen localhost:5000
<VirtualHost localhost:5000>

Alias /favicon.ico c:/inetpub/WebApp/root/favicon.ico
Alias /static/ c:/inetpub/WebApp/root/static/
Alias / c:/inetpub/WebApp/script/webapp_fastcgi.pl/

<Directory c:/inetpub/WebApp/script>
Options ExecCGI
SetHandler fastcgi-script
</Directory>

<Location />
AuthName "Use your DOMAIN account"
AuthType SSPI
SSPIAuth On
SSPIAuthoritative On
require valid-user
Order allow,deny
Allow from all
</Location>

</VirtualHost>

Now you can use Catalyst::Authentication::Credential::Remote to integrate your catalyst application with the authentication performed on Apache level.

My tags:
 
Popular tags:
 
Powered by Catalyst
Powered by MojoMojo Hosted by Shadowcat - Managed by Nordaaker