[Catalyst-dev] Deployment tutorial from newbie for newbies

Dan Dascalescu ddascalescu+catalyst at gmail.com
Fri Dec 15 01:31:59 GMT 2006


I finally managed to get my app running under FastCGI as I wanted it
to, and thought this may be useful for the advent calendar or
somewhere else on the Catalyst blog:

<konobi> sounds like the advent calendar really needs a deployment entry

Please edit as you see fit. I'm very well aware that I'm very new to
Catalyst and might have written stuff that's not quite right.

---8<---
FastCGI deployment that works

Hello everyone. I'm a Catalyst newbie and as Matt S Trout himself once
said, "newbies write the best docs". I'm writing this entry in the
advent calendar because I just managed to get Catalyst running in
"production" mode, after a few days of frustration with FastCGI.

As a background for this article, you may want to read, but certainly
don't have to:
 http://search.cpan.org/dist/Catalyst-Runtime/lib/Catalyst/Engine/FastCGI.pm
 http://search.cpan.org/~jrockway/Catalyst-Manual-5.700501/lib/Catalyst/Manual/Cookbook.pod#Deployment

I went the FastCGI route because it offers the same speed as mod_perl,
but allows you to restart your app without restarting the whole Apache
server.

There are also some other entries in the Catalyst advent calendar
about FastCGI deployment, but they didn't work for me:
 http://www.catalystframework.org/calendar/2006/4 - I was new to
FastCGI and didn't need the bells and whistles
 http://www.catalystframework.org/calendar/2005/17 doesn't work, at
least on the FreeBSD 4 box I'm confined to.

It didn't work for two reasons:
1. -d did not cause myapp to get demonized
2. apache could never connect to the socket (the error was "connect() failed)

There are three ways to go FastCGI: static, dynamic and external.
External is the most flexible and the simplest way to restart your app
without restarting the entire server.

To go external without sockets, use a TCP pipe:

httpd.conf:
 FastCgiExternalServer
/home/dandv/public_html/myapp/script/myapp_fastcgi.pl -host
127.0.0.1:55900
 Alias / /home/dandv/public_html/myapp/script/myapp_fastcgi.pl/

Launch your application as
 script/myapp_fastcgi.pl -e -l 127.0.0.1:5678 -p /tmp/myapp.pid

The -e switch causes you application's STDERR output to go to the
screen, instead of ending up in Apache's error log. Launch
myapp_fastcgi.pl --help and check if its usage displays the "-e"
parameter. If not, you need to have the latest version of
"Catalyst::Devel":

 perl -MCPAN -e "install Catalyst::Devel"

You also need to regenerate the helper scripts. You can do this by launching

 catalyst.pl myapp2

and replacing myapp2 with myapp in all .pl files that get generated.

Now you are ready to enjoy full logging by using Log4perl (excellent
tutorial at http://www.catalystframework.org/calendar/2006/11) and by
launching your app as:
 script/myapp_fastcgi.pl -e -l 127.0.0.1:5678 -p /tmp/myapp.pid 2> stderr.log
--->8---

A note about C::P::Log4perl: from what I've read, it's not very
obvious how (or if) it can log the warnings that Perl produces to
STDERR (such as "Use of uninitialized value..."). That's why I hunted
the -e switch in myapp_fastcgi. If there's a Log4perl solution to
this, maybe the advent entry for Log4perl could be amended. I already
e-mailed Kennedy Clark about this.

Hope this helps,
Dan Vlad Dascalescu



More information about the Catalyst-dev mailing list