Catalyst

adventures in webdev with perl

Catalyst on shared hosting

So, you want to put your Catalyst app out there for the whole world to see, but you don't want to break the bank. There is an answer - if you can get shared hosting with FastCGI and a shell, you can install your Catalyst app. First, run

perl -MCPAN -e shell

and go through the standard CPAN configuration process. Then exit out without installing anything. Next, open your .bashrc and add

export PATH=$HOME/local/bin:$HOME/local/script:$PATH
perlversion=`perl -v | grep 'built for' | awk '{print $4}' | sed -e 's/v//;'`
export PERL5LIB=$HOME/local/share/perl/$perlversion:$HOME/local/lib/perl/$perlversion:$HOME/local/lib:$PERL5LIB

and log out, then back in again (or run ". .bashrc" if you prefer). Finally, edit .cpan/CPAN/MyConfig.pm and add

'make_install_arg' => qq[SITEPREFIX=$ENV{HOME}/local],
'makepl_arg' => qq[INSTALLDIRS=site install_base=$ENV{HOME}/local],

Now you can install the modules you need with CPAN as normal, and perl will pick them up. Finally, change directory into the root of your virtual host and symlink your application's script directory in -

cd path/to/mydomain.com
ln -s ~/lib/MyApp/script script

And add the following lines to your .htaccess file (assuming the server is setup to handle .pl as fcgi - you may need to rename the script to myapp_fastcgi.fcgi and/or use a SetHandler directive) -

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/?script/myapp_fastcgi.pl
RewriteRule ^(.*)$ script/myapp_fastcgi.pl/$1 [PT,L]

http://mydomain.com/ should now Just Work. Congratulations, now you can tell your friends about your new website (or in our case, tell the client it's time to pay the invoice :)

-- mst

cookbook : original article