I'm attempting to deploy the Dancer2::Tutorial app with Plack::Handler::Apache2 and having problems implementing Sessions using the following setup:
config.yml

appname: "TestSession" layout: "main" charset: "UTF-8" # session setup session: YAML engines: session: YAML: session_dir: /tmp/dancer-sessions # template engine template: "template_toolkit" engines: template: template_toolkit: start_tag: '[%' end_tag: '%]'

app.pl

#!/usr/bin/env perl use FindBin; use lib "$FindBin::Bin/../lib"; use TestSession; TestSession->dance;

TestSession.pm code

package TestSession; use Dancer2; our $VERSION = '0.11'; use DBI; use File::Spec; use File::Slurp; use Template; set 'logger' => 'file'; set 'log' => 'debug'; set 'show_errors' => 1; set 'startup_info' => 1; set 'warnings' => 1; set 'username' => 'admin'; set 'password' => 'password'; set 'layout' => 'main'; my $timestamp = localtime; my $login_status; my $dbh = DBI->connect('DBI:mysql:testsession','test','dr_dfRFgt@');\ my $flash; sub set_flash { my $message = shift; $flash = $message; } sub get_flash { my $msg = $flash; $flash = ""; return $msg; } hook before_template => sub { my $tokens = shift; $tokens->{'session_logged_in'} = session('logged_in'); $tokens->{'css_url'} = request->base . 'css/style.css'; $tokens->{'login_url'} = uri_for('/login'); $tokens->{'logout_url'} = uri_for('/logout'); }; get '/' => sub { my $sql = 'select id, etitle, etext from entries order by id desc +'; my $sth = $dbh->prepare($sql) or die $dbh->errstr; $sth->execute or die $sth->errstr; template 'show_entries.tt', { 'session_logged_in' => session('logged_in'), 'msg' => get_flash(), 'add_entry_url' => uri_for('/add'), 'entries' => $sth->fetchall_hashref('id'), }; }; post '/add' => sub { if (not $login_status) { debug "add route attempted with login_status $login_status"; send_error("Not logged in", 401); } debug "login_status $login_status: adding entry on status $login_ +status"; my $sql = 'insert into entries (etitle, etext) values (?, ?)'; my $sth = $dbh->prepare($sql) or die $dbh->errstr; $sth->execute(params->{'etitle'}, params->{'etext'}) or die $sth- +>errstr; set_flash('New entry posted!'); redirect '/'; }; any ['get', 'post'] => '/login' => sub { my $err; if ( request->method() eq "POST" ) { debug "executing login attempt\n"; # process form input if ( params->{'username'} ne setting('username') ) { $err = "Invalid username"; debug "Got Invalid username"; } elsif ( params->{'password'} ne setting('password') ) { $err = "Invalid password"; debug "Got Invalid password"; } else { debug "Login Successful"; session logged_in => true; $login_status = 1; debug "login_status:".session('logged_in'); set_flash('You are logged in.'); redirect '/'; } } # display login form template 'login.tt', { 'err' => $err, }; }; get '/logout' => sub { debug "login:\t executng LOGOUT\n"; context->destroy_session; $login_status = 0; debug "login_status on LOGOUT:\t$login_status"; set_flash('You are logged out.'); debug "login LOGOUT flash message: ".$flash; redirect '/'; }; start; true;

Apache 2 virtualhosts.conf entry.

<VirtualHost 96.0.255.146:80> ServerAdmin webmaster@dataship.com DocumentRoot /var/www/retireaboard/RetireAboard ServerName retireaboard.com <Directory "/var/www/retireaboard/RetireAboard"> AllowOverride None Order allow,deny Allow from all </Directory> <Location /> SetHandler perl-script PerlResponseHandler Plack::Handler::Apache2 PerlSetVar psgi_app /var/www/retireaboard/RetireAboard/bin/app +.pl </Location> SetEnv DANCER_ENVIRONMENT "development" ErrorLog /var/log/httpd/www.retireaboard.com.log CustomLog /var/log/httpd/retireaboard_access.log combined </VirtualHost>

httpd error log

[Wed Nov 27 01:15:53 2013] [error] [client 24.86.10.67] Error while lo +ading /var/www/retireaboard/RetireAboard/bin/app.pl: Unable to create + session dir : ./sessions : Permission denied at (eval 135) line 11\n +Compilation failed in require at /var/www/retireaboard/RetireAboard/b +in/app.pl line 6.\nBEGIN failed--compilation aborted at /var/www/reti +reaboard/RetireAboard/bin/app.pl line 6.\n

Using Plack::Handler::Apache2 to deploy the app with Apache2 causes the compile to fail. The app is unable to create a ./session dir despite having full rwx permissions for the appdir.
Exactly the same failure occurs for JSON sessions.
Is there further Plack setup required in the .pm file?


In reply to Dancer2 sessions under Plack by fishboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.