Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found