Deploying a Dancer app with perlbrew under Apache
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)
On 05/02/2014 11:55 AM, Joel Roth wrote:
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.
Thanks a lot for providing this for other users! CGI is old and should die though. Even if you are stuck with it, FastCGI is a more viable and faster way to run CGI scripts. Regards Racke -- LinuXia Systems => http://www.linuxia.de/ Expert Interchange Consulting and System Administration ICDEVGROUP => http://www.icdevgroup.org/ Interchange Development Team
On Fri, 2 May 2014, Stefan Hornburg (Racke) wrote:
CGI is old and should die though. Even if you are stuck with it, FastCGI is a more viable and faster way to run CGI scripts.
CGI is old, but it should not die! It's still useful in a few limited cases, such as very low RAM and/or rarely-run web apps. I'm not suggesting that any normal web app use it, of course, but "should die" is a bit much. :) Jon -- Jon Jensen End Point Corporation http://www.endpoint.com/
On 2014-05-02, at 12:50 PM, Jon Jensen wrote:
On Fri, 2 May 2014, Stefan Hornburg (Racke) wrote:
CGI is old and should die though. Even if you are stuck with it, FastCGI is a more viable and faster way to run CGI scripts.
CGI is old, but it should not die! It's still useful in a few limited cases, such as very low RAM and/or rarely-run web apps.
I'm not suggesting that any normal web app use it, of course, but "should die" is a bit much. :)
Recently I actually found myself working with CGI scripts to write tests for an Apache module at $work. I kind of thought I was done with CGI, but in this particular case it came in very handy: https://github.com/maxmind/mod_maxminddb/tree/master/t/cgi-bin Olaf -- Olaf Alders olaf@wundersolutions.com http://www.wundersolutions.com http://twitter.com/wundercounter
On 05/02/2014 06:50 PM, Jon Jensen wrote:
On Fri, 2 May 2014, Stefan Hornburg (Racke) wrote:
CGI is old and should die though. Even if you are stuck with it, FastCGI is a more viable and faster way to run CGI scripts.
CGI is old, but it should not die! It's still useful in a few limited cases, such as very low RAM and/or rarely-run web apps.
It should die. Period. For the few limited cases, find a PSGI solution. Maybe inetd? And these cases are very few IMHO.
I'm not suggesting that any normal web app use it, of course, but "should die" is a bit much. :)
Yeah, well :-). I value your opinion, but mine is as above. Regards Racke -- LinuXia Systems => http://www.linuxia.de/ Expert Interchange Consulting and System Administration ICDEVGROUP => http://www.icdevgroup.org/ Interchange Development Team
On Fri, May 02, 2014 at 11:02:25PM +0200, Stefan Hornburg (Racke) wrote:
On 05/02/2014 06:50 PM, Jon Jensen wrote:
On Fri, 2 May 2014, Stefan Hornburg (Racke) wrote:
CGI is old and should die though. Even if you are stuck with it, FastCGI is a more viable and faster way to run CGI scripts. CGI is old, but it should not die! It's still useful in a few limited cases, such as very low RAM and/or rarely-run web apps. It should die. Period. For the few limited cases, find a PSGI solution. Maybe inetd? And these cases are very few IMHO.
I think it's reasonable to say that CGI is always wrong if your application can justify using a framework as big and heavy as Dancer, but there are plenty of cases where the extreme simplicity of CGI makes it a clear winner. That simplicity is why CPANdeps, for example, uses CGI. Things like Dancer and mod_perl would just get in the way. Another good reason to write CGI-based code is if you've already got an application that uses it and works just fine. Provided that you can add functionality using CGI while still keeping the application maintainable, then it's better to do that than to port to something fancier. -- David Cantrell | A machine for turning tea into grumpiness Deck of Cards: $1.29. "101 Solitaire Variations" book: $6.59. Cheap replacement for the one thing Windows is good at: priceless -- Shane Lazarus
On Fri, May 02, 2014 at 02:02:39PM +0200, Stefan Hornburg (Racke) wrote:
On 05/02/2014 11:55 AM, Joel Roth wrote:
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.
Thanks a lot for providing this for other users!
CGI is old and should die though. Even if you are stuck with it, FastCGI is a more viable and faster way to run CGI scripts.
Thanks for the suggestion, Racke. I'll look into FastCGI. My particular app is a flat-file CMS, and the traffic is low, so CGI is still a good fit. Kind regards, Joel
Regards Racke
-- LinuXia Systems => http://www.linuxia.de/ Expert Interchange Consulting and System Administration ICDEVGROUP => http://www.icdevgroup.org/ Interchange Development Team
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- Joel Roth
Stefan Hornburg (Racke) wrote:
CGI is old and should die though. Even if you are stuck with it, FastCGI is a more viable and faster way to run CGI scripts.
For testing, and for newbies, CGI is still convenient. I do experience a fairly long lag while pages are loaded. Greetings Joel
Regards Racke
-- LinuXia Systems => http://www.linuxia.de/ Expert Interchange Consulting and System Administration ICDEVGROUP => http://www.icdevgroup.org/ Interchange Development Team
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- Joel Roth
From: "Joel Roth" <joelz@pobox.com>
Stefan Hornburg (Racke) wrote:
CGI is old and should die though. Even if you are stuck with it, FastCGI is a more viable and faster way to run CGI scripts.
For testing, and for newbies, CGI is still convenient. I do experience a fairly long lag while pages are loaded.
Greetings Joel
When we are talking on a mailing list dedicated to a web framework so we are probably thinking to use CGI with a web framework, then yes, CGI is not recommended. But not all the sites use a CMS or web framework or ORM, or templating system. There may be very simple scripts which are used just once a week or month, and not by the public but by a sysadmin for doing some settings. In those cases using CGI is better than psgi, because they are more convenient to create and don't stay loaded in memory and consume resources for no reason. And I don't see why CGI should die while for those sysadmins is more helpful than other solutions. Octavian
On 05/03/2014 08:00 AM, Octavian Rasnita wrote:
From: "Joel Roth" <joelz@pobox.com>
Stefan Hornburg (Racke) wrote:
CGI is old and should die though. Even if you are stuck with it, FastCGI is a more viable and faster way to run CGI scripts.
For testing, and for newbies, CGI is still convenient. I do experience a fairly long lag while pages are loaded.
Greetings Joel
When we are talking on a mailing list dedicated to a web framework so we are probably thinking to use CGI with a web framework, then yes, CGI is not recommended. But not all the sites use a CMS or web framework or ORM, or templating system.
There may be very simple scripts which are used just once a week or month, and not by the public but by a sysadmin for doing some settings. In those cases using CGI is better than psgi, because they are more convenient to create and don't stay loaded in memory and consume resources for no reason.
And I don't see why CGI should die while for those sysadmins is more helpful than other solutions.
I don't use any CGI scripts for my sysadmin part of work, but of course normal Perl scripts executed from the command line or cron. Some of these are now written in Dancer, which is useful to share configuration and modules with your web projects. I don't mind people using CGI, but I don't see a purpose of them for my work. Regards Racke -- LinuXia Systems => http://www.linuxia.de/ Expert Interchange Consulting and System Administration ICDEVGROUP => http://www.icdevgroup.org/ Interchange Development Team
From: "Stefan Hornburg (Racke)" <racke@linuxia.de>
On 05/03/2014 08:00 AM, Octavian Rasnita wrote:
From: "Joel Roth" <joelz@pobox.com>
Stefan Hornburg (Racke) wrote:
CGI is old and should die though. Even if you are stuck with it, FastCGI is a more viable and faster way to run CGI scripts.
For testing, and for newbies, CGI is still convenient. I do experience a fairly long lag while pages are loaded.
Greetings Joel
When we are talking on a mailing list dedicated to a web framework so we are probably thinking to use CGI with a web framework, then yes, CGI is not recommended. But not all the sites use a CMS or web framework or ORM, or templating system.
There may be very simple scripts which are used just once a week or month, and not by the public but by a sysadmin for doing some settings. In those cases using CGI is better than psgi, because they are more convenient to create and don't stay loaded in memory and consume resources for no reason.
And I don't see why CGI should die while for those sysadmins is more helpful than other solutions.
I don't use any CGI scripts for my sysadmin part of work, but of course normal Perl scripts executed from the command line or cron.
Some of these are now written in Dancer, which is useful to share configuration and modules with your web projects.
I don't mind people using CGI, but I don't see a purpose of them for my work.
Regards Racke
I also don't use CGI... usually, but in some cases the sysadmin just offers a directory where you can place CGI scripts that will be loaded by Apache, because they need to be used by non-technical people to input some data once in a while. So CLI scripts are not a solution, mod_perl/fastcgi/psgi are not a solution either, and even if they would be, CGI would still be easier for simple scripts. And they can also share configuration files, use different modules etc. Octavian
On Sat, May 03, 2014 at 09:00:39AM +0300, Octavian Rasnita wrote:
There may be very simple scripts which are used just once a week or month, and not by the public but by a sysadmin for doing some settings. In those cases using CGI is better than psgi, because they are more convenient to create and don't stay loaded in memory and consume resources for no reason.
If it's only used once a week it won't stay loaded in memory, it'll get swapped out if there are other tasks that need the memoryi or bits of the filesystem to cache. Reading it back from swap will be no slower than CGI. If you're worried about it taking resources in the swap slice, then you're doing your sysadminning wrong! -- David Cantrell | London Perl Mongers Deputy Chief Heretic What is the difference between hearing aliens through the fillings in your teeth and hearing Jesus in your heart?
On 5/6/2014 05:36, David Cantrell wrote:
On Sat, May 03, 2014 at 09:00:39AM +0300, Octavian Rasnita wrote:
There may be very simple scripts which are used just once a week or month, and not by the public but by a sysadmin for doing some settings. In those cases using CGI is better than psgi, because they are more convenient to create and don't stay loaded in memory and consume resources for no reason.
If it's only used once a week it won't stay loaded in memory, it'll get swapped out if there are other tasks that need the memoryi or bits of the filesystem to cache. Reading it back from swap will be no slower than CGI.
Reading from cache skips the parsing and require/use resolution steps. The savings from compiling Dancer into the intermediate form alone should be worthwhile. $ time 'perl -e print "x"' x real 0m0.001s user 0m0.000s sys 0m0.002s $ time perl -e 'use Dancer;print "x"' x real 0m0.535s user 0m0.110s sys 0m0.012s Half a second of page load latency is quite noticeable.
On Tue, May 06, 2014 at 11:49:15AM -0600, Warren Young wrote:
On 5/6/2014 05:36, David Cantrell wrote:
If it's only used once a week it won't stay loaded in memory, it'll get swapped out if there are other tasks that need the memoryi or bits of the filesystem to cache. Reading it back from swap will be no slower than CGI. Reading from cache skips the parsing and require/use resolution steps. The savings from compiling Dancer into the intermediate form alone should be worthwhile.
...
Half a second of page load latency is quite noticeable.
Noticeable, but of no consequence if you're using it so seldom that the application gets swapped out. -- David Cantrell | Enforcer, South London Linguistic Massive "Cynical" is a word used by the naive to describe the experienced. George Hills, in uknot
participants (7)
-
David Cantrell -
Joel Roth -
Jon Jensen -
Octavian Rasnita -
Olaf Alders -
Stefan Hornburg (Racke) -
Warren Young