[tpm] Deploying Mojolicious Apps

Zoffix Znet zoffixznet at gmail.com
Thu Oct 29 15:18:56 PDT 2015


Hey,

Someone emailed me asking to clarify deployment... I wrote a large
response, so I figured I may as well share it to the list, if anyone
else had the same question:


If all you have is shared hosting... tough luck: Although it's possible
to run Mojolicious apps as CGI scripts
(http://mojolicio.us/perldoc/Mojolicious/Guides/Cookbook#Apache-CG ),
it's by far less than ideal, since you'll be starting your app up for
each request—and that's slow.

The proper way to do it is to have your Mojolicious app run
continuously. That's usually a problem on shared hosts, because the
system will kill any process that runs too long (1and1 shared hosting
kills them after about 30 seconds of run time, for example).

What you could do (and how I did it) is get a VPS from Linode
(https://www.linode.com/ ). It's just $10/month, so the cost is
comparable to shared hosting.

What that gives you is essentially your own server. You can install
anything you want on it. On mine, I installed Debian Linux, along with
Apache.

Then, I saved this file in /etc/apache2/sites-available/, named
xtatik.org.conf

	<VirtualHost *:80>
	  ServerName xtatik.org
	  <Proxy *>
	    Order deny,allow
	    Allow from all
	  </Proxy>
	  ProxyRequests Off
	  ProxyPreserveHost On
	  ProxyPass / http://localhost:8081/ keepalive=On
	  ProxyPassReverse / http://localhost:8081/
	  RequestHeader set X-Forwarded-Proto "http"
	</VirtualHost>

Notice the "8081" port number; that's the port my Mojolicious app is
listening on. Then I just enable that site in Apache (a2ensite
xtatik.org) and restart the server(apache2ctl restart) and now Apache
will forward any requests for "xtatik.org" to my Mojolicious app.

Now, in my app, I configure Hypnotoad to serve on port 8081 as well
(replace "$self", the Mojolicious::Controller, with "app" for ::Lite
apps):

	$self->config(hypnotoad => {listen => ['http://*:8081']});

At this point, you can simply run:
	
	hypnotoad YourApp.pl

And hypnotoad will start up your app, and visiting xtatik.org would now
show the content generated by my app.... but, you don't wanna do that
manually every time your server reboots, so what you can do is use
Toadfarm (https://metacpan.org/pod/Toadfarm ) to start up all of your
apps.

And just to note: if you have only a single app, nothing's stopping you
from foregoing Apache and just telling hypnotoad to listen on port :80
(or :443 for HTTPS). Many people also use nginx server instead of Apache
due to lower resource requirements, but I was already familiar with
Apache, so I went with that.

Hope that helps! :)

Cheers,
ZZ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20151029/335c3420/attachment.html>


More information about the toronto-pm mailing list