After hacking together enough of a project management system that it could manage its own further development, I decided to try deploying it to my personal project VM before I went to bed.
I had previously installed Phusion Passenger on my personal projects VM, so I figured this would be a five minute job. It wasn’t.
But I’m getting ahead of myself.
If you want to deploy your app with Passenger, which you very well might since it means you don’t need to faff around with proxying and ports and the normal nonsense associated with deploying Rails apps, you first need to install and configure Passenger.
Installing is really, really easy, assuming that you’ve already got Ruby and Rubygems installed. The install instructions pretty much cover it, however there is one gotcha:
After you’ve installed the gem (with gem install passenger) you need to run the appropriate script to configure Apache. The instructions imply this is as simple as typing passenger-install-apache2-module, but that assumes you have the gems bin directory in your path which, on Ubuntu, I didn’t.
A quick locate passenger-install-apache2-module later and I had the full path to the script.
The script will give you some stuff to put in your Apache config file. For me this was /etc/apache2/httpd.conf – if you’re not using Ubuntu, you might find it elsewhere, possibly under /etc/httpd/.
Restart Apache and create a standard virtual host that points to the public/ directory of your Rails app, like the one below, and it should just magically work!
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/john/deploy/example/public
</VirtualHost>
Sadly, it doesn’t just magically work unless your Ruby and Rails versions are exactly the same on the development and production machines, which is pretty unlikely. Fiddling around to upgrade Rubygems on my VM I managed to break several things and generally caused a mess that’s not quite cleaned up yet. This would be simpler, but for Ubuntu’s outdated RubyGems support, but even if Ubuntu had the latest RubyGems there would undoubtedly be other version issues since I was developing on Mac OS X and not Ubuntu.
There’s a really simple solution to this, though: just freeze rails into vendor/. A simple rake freeze:gems and your development Rails gems are happily slurped into the project where they can be version controlled and deployed to your production machine.
Because I was using a git repo to share code with Craig my actual initial deploy was to just git-clone from the repo, with a git-pull when I’d made changes. I think that on a larger project you’d be using the awesome Capistrano to automate the process.
I’ve looked at deploying Rails apps in the past, and it’s always seemed like a huge pain, with front-facing web servers like Apache doing proxying to Mongrel or whatever. Running more than one app on the same host was a huge pain. Passenger makes the whole thing easy – once it’s installed it makes managing Rails’ web servers just managing Apache. If you have existing skills with Apache (and who managing a web host doesn’t?) the whole thing suddenly becomes quick, easy, and fun.
After I’ve got the basic application working, and before I move on to the ‘making it good’ usability features, I think I might experiment with Ruby Enterprise Edition and deploying to a MySQL DB (instead of the quick-and-easy SQLite3 production DB I’m using at the moment). I think that would more accurately reflect the environment for a larger app that had more than one user.
Post a Comment