[dancer-users] Deploying a Dancer app with perlbrew under Apache
Joel Roth
joelz at pobox.com
Fri May 2 10:55:28 BST 2014
Hi list,
Having struggled a while to get a Dancer app working with
perlbrew on a shared host with the Apache webserver, I'm
documenting it for others. Please let me know if you
think it is useful, or have any suggestions.
Joel
--
Deploying a Dancer app with perlbrew under Apache
I'll assume you've successfully installed perlbrew, so
that (for example) typing
perlbrew use 5.16.3; perl -v
shows you the correct perl version.
On my shared host, the requests are handled by a CGI script
in the document root for the site called dispatch.cgi:
#!/bin/sh
source ~/.bashrc # you need this for the correct environment
perlbrew use 5.16.3 # and this for the correct perl
exec `dirname $0`/plack_runner.pl ${1+"$@"}
I use mod-rewrite to prepend "dispatch.cgi" to the routes
when required, thereby eliminating the name of the script
from links to the site. The file .htaccess, in the document
root, contains this code:
# BEGIN dancer application htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) dispatch.cgi/$1
# END dancer application htaccess
dispatch.cgi calls plack_runner.pl, also in the document
root:
#!/usr/bin/env perl
use autodie;
use Plack::Runner;
chdir '/home/username/app_dir';
Plack::Runner->run('app.psgi');
plack_runner.pl runs app.psgi, which lives in the app_dir.
#!/usr/bin/env perl
BEGIN { push @ARGV, qw(--environment=production) }
use lib ('/home/username/app_dir/lib');
use Dancer;
load_app 'danceapp';
dance;
To test the website locally on my laptop, I run app.psgi
from the command line and point my browser at
http://localhost:3000. (I use the same directory path for
the app_dir on my laptop as on the production site.)
To make several similar websites using the same app code, I
converted danceapp.pm to a module and installed it
conventionally using perlbrew and cpanm.
perlbrew use 5.16.3
cpanm My-Dancer-App-0.1.tar.gz
With the app implemented this way, the 'use lib' line in
app.psgi is not required.
(END)
More information about the dancer-users
mailing list