[Catalyst-dev] Tutorial Fails under Apache Mod_Perl

William Anderson william_anderson at yahoo.com
Thu Dec 5 17:40:41 GMT 2013


Perl Catalyst Problem

Hi all,

I have a bit of a problem with Catalyst. I have been working through the Ca=
talyst tutorial as found at http://search.cpan.org/~ether/Catalyst-Manual-5=
.9007/lib/Catalyst/Manual/Tutorial.pod . First off, this is a very good int=
roduction to Catalyst development. I have completed chapters 0 to 8, and th=
e code that I have entered works flawlessly when run using the myapp_server=
.pl. this was initally done on the provided Catalyst tutorial virtual machi=
ne image downloaded from http://cattut.shadowcat.co.uk/. =


I have since moved this to my own development server, and it also works fla=
wlessly when using the myapp_server.pl script on the new computer. =


My problem is that, the exact same code, running on the exact same developm=
ent computer, blows up when running as a mod_perl module under Apache. When=
 I attempt to log in, I get the following error:
=A0=A0=A0 Caught exception in MyApp::Controller::Login->index "Can't use st=
ring
=A0=A0=A0 =A0("Catalyst::Authentication::Store:"...) as a HASH ref while "s=
trict =

=A0=A0=A0 =A0refs" in use at accessor Catalyst::Authentication::Store::DBIx=
::Class
=A0=A0=A0 =A0::User::_user (defined at /usr/share/perl5/Catalyst/Authentica=
tion/
=A0=A0=A0 =A0Store/DBIx/Class/User.pm line 12) line 5, <DATA> line 1000."

The stack trace points the failure at the line where the $c->authenticate m=
ethod is called:
=A0=A0 35: =A0=A0=A0 if ($username && $password) {
=A0=A0 36: =A0=A0=A0 =A0=A0=A0 # Attempt to log the user in
=A0=A0 37: =A0=A0=A0 =A0=A0=A0 $c->log->debug("value in \$c->authenticate i=
s \"".Dumper($c)."\""); =

=A0=A0 38: =A0=A0=A0 =A0=A0=A0 if ($c->authenticate({ username =3D> $userna=
me,
=A0=A0 39: =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=
=A0=A0 =A0=A0 password =3D> $password=A0 } )) {
=A0=A0 40: =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 # If successful, then let them use=
 the application
=A0=A0 41: =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 $c->response->redirect($c->uri_for(

if i add a debug or print statement before this. the error moves to the fir=
st place where I reference the $c context object.

Again, this exact same code works with no problem when run using the myapp_=
server.pl. this is the only difference, the host name is the same, the ip a=
ddress is the same, the code is the same, the installed perl libraries are =
the same, the difference in the url is one is accessed using port 3000 and =
the other is=A0 at port 80 (http://mytest.org:3000/ vs http://mytest.org/ )=
. =


My environment:
My web development server is runnung Ubuntu 13.10 Server in a Virtualbox VM=
. =

I have downloaded and installed Catalyst mostly using the packages availabl=
e in the Ubuntu 13.10 repositories, although a small hand full of perl modu=
les used by the tutorial Catalyst had to be installed via CPAN using the Ca=
talyst project Makefile. except for a couple of PHP modules and the Catalys=
t stuff, this is a fresh, vanilla install of Ubuntu 13.10, choosing to inst=
all the LAMP, SSH server, and Mail Server package groups during the install=
ation.

The apache2 configuration file, enabling the site under mod_perl on apache:
=A0=A0 $ cat /etc/apache2/sites-enabled/004-osws-catalyst-site.conf
=A0=A0 PerlSwitches=A0=A0=A0 -I/home/onestopw/lib
=A0=A0 PerlModule=A0=A0=A0=A0=A0 MyApp

=A0=A0 <VirtualHost mytest.org:80>
=A0=A0=A0=A0=A0=A0=A0 # The ServerName directive sets the request scheme, h=
ostname and port that
=A0=A0=A0=A0=A0=A0=A0 # the server uses to identify itself. This is used wh=
en creating
=A0=A0=A0=A0=A0=A0=A0 # redirection URLs. In the context of virtual hosts, =
the ServerName
=A0=A0=A0=A0=A0=A0=A0 # specifies what hostname must appear in the request'=
s Host: header to
=A0=A0=A0=A0=A0=A0=A0 # match this virtual host. For the default virtual ho=
st (this file) this
=A0=A0=A0=A0=A0=A0=A0 # value is not decisive as it is used as a last resor=
t host regardless.
=A0=A0=A0=A0=A0=A0=A0 # However, you must set it for any further virtual ho=
st explicitly.
=A0=A0=A0=A0=A0=A0=A0 ServerName osws.org

=A0=A0=A0=A0=A0=A0=A0 ServerAdmin webmaster at localhost
=A0=A0=A0=A0=A0=A0=A0 DocumentRoot /home/onestopw/root

=A0=A0=A0=A0=A0=A0=A0 # Available loglevels: trace8, ..., trace1, debug, in=
fo, notice, warn,
=A0=A0=A0=A0=A0=A0=A0 # error, crit, alert, emerg.
=A0=A0=A0=A0=A0=A0=A0 # It is also possible to configure the loglevel for p=
articular
=A0=A0=A0=A0=A0=A0=A0 # modules, e.g.
=A0=A0=A0=A0=A0=A0=A0 #LogLevel info ssl:warn

=A0=A0=A0=A0=A0=A0=A0 ErrorLog=A0 /home/onestopw/logs/error.log
=A0=A0=A0=A0=A0=A0=A0 CustomLog /home/onestopw/logs/access.log combined

=A0=A0=A0=A0=A0=A0=A0 # For most configuration files from conf-available/, =
which are
=A0=A0=A0=A0=A0=A0=A0 # enabled or disabled at a global level, it is possib=
le to
=A0=A0=A0=A0=A0=A0=A0 # include a line for only one particular virtual host=
. For example the
=A0=A0=A0=A0=A0=A0=A0 # following line enables the CGI configuration for th=
is host only
=A0=A0=A0=A0=A0=A0=A0 # after it has been globally disabled with "a2disconf=
".
=A0=A0=A0=A0=A0=A0=A0 #Include conf-available/serve-cgi-bin.conf

=A0=A0=A0=A0=A0=A0=A0 # run the app from the site root directory
=A0=A0=A0=A0=A0=A0=A0 <Location />
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 SetHandler=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0 modperl
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 PerlResponseHandler=A0=A0=A0=
=A0 MyApp
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 #Options Indexes FollowSymLin=
ks
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Order Deny,Allow
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Allow from all
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Require all granted
=A0=A0=A0=A0=A0=A0=A0 </Location>

=A0=A0=A0=A0=A0=A0=A0 # however, server static content with apache alone
=A0=A0=A0=A0=A0=A0=A0 <Location /static>
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 SetHandler=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0 default-handler
=A0=A0=A0=A0=A0=A0=A0 </Location>


=A0=A0 </VirtualHost>

=A0=A0 # vim: syntax=3Dapache ts=3D4 sw=3D4 sts=3D4 sr noet

this apache.conf file was modeled on the file described at http://search.cp=
an.org/~flora/Catalyst-Engine-Apache-1.16/lib/Catalyst/Engine/Apache2/MP20.=
pm

the site starts to work under apache mod_perl and the login page is display=
ed whenever any url to this site is loaded. this is also exactly what happe=
ns when run using the myapp_server.pl when no user is logged in. When I sup=
ply a user name and password on the login form and submit the form, that is=
 when the above error occurs when running under mod_perl. When run by the m=
yapp_server.pl script, submitting the form validates the user and password,=
 and if valid, displays the book list page. =


I believe that this error is caused by the Catalyst object not being proper=
ly blessed when running as a mod_perl module. This means that when the auth=
enticate method is called, instead of $c being a context object with an aut=
henticate method, it is simply a string containing "Catalyst::Authenticatio=
n::Store:", the name of the object type that it is supposed to be.
=A0
At this point, I am at a loss. Something is different between the apache mo=
d_perl environment and the myapp_server.pl environment. I am currently step=
ping through the execution of loading and configuration of the MyApp module=
, placing print STDERR lines throughout the Catalyst modules as MyApp.pm is=
 loaded. Hopefully, the difference will become apparent, but if anyone more=
 familiar with the inner workings of Catalyst sees something obvious, pleas=
e let me know. =


My project is stuck in the mud at this point, since there would be no point=
 in developing it using Catalyst if Catalyst will not actually work under a=
pache.

Thanks,

William Anderson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst-dev/attachments/20131205/7=
b93c032/attachment.htm


More information about the Catalyst-dev mailing list