mod_rails go!
This post is a guide to setting up passenger (or mod_rails) on an ubuntu server.
Passenger is an apache module that finally lets you run stable rails applications on the worlds most popular webserver
And setting it up is simpler than mongrel! This guide will start from the very start, as in assuming you have just installed ubuntu.
First step is to update your aptitiude to install the latest versions of everything
sudo aptitude full-upgrade
Ok, now we can start to install stuff.
First, Install some basic development tools, as in gcc make etc…
sudo aptitude install build-essential
Next, install ruby, which at the time was 1.8.6
sudo aptitude install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby sqlite3 libsqlite3-ruby1.8
you may need to create these symlinks
sudo ln -s /usr/bin/ruby1.8 /usr/bin/ruby
sudo ln -s /usr/bin/ri1.8 /usr/bin/ri
sudo ln -s /usr/bin/rdoc1.8 /usr/bin/rdoc
sudo ln -s /usr/bin/irb1.8 /usr/bin/irb
Next, install rubygems. This is done from source instead of aptitude due to aptitude having ancient versions of rubygems. Latest rubygems at the time of writing this is version 1.2.0
wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
Then extract this archive and jump into the extracted folder, then run
sudo ruby setup.rb
symlink if needed
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
Then run the update command just off principle
sudo gem update --system
Next we can install rails!
sudo gem install rails
Next we can install rails mail sending support, and also version control tools needed for later on such as subversion and git.
sudo aptitude install postfix subversion git-core
Next, we can install MySQL and the required ruby bindings, this is of course if you were using a MySQL database
sudo aptitude install mysql-server libmysqlclient-dev
sudo gem install mysql
Ok, now the change from how you would of set up a server with mongrel. Time to install apache!
sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert apache2-prefork-dev
then to fix the annoying error whenever you restart apache, add
ServerName yourservername
to bottom of /etc/apache2/apache2.conf
then restart apache
/etc/init.d/apache2 restart
Next we can install passenger, the module needed by apache to run the rails application
sudo gem install passenger
then run
sudo passenger-install-apache2-module
and follow the instructions
Ok, we are almost there! All that we need now is some apache configuration.
go to /etc/apache2/sites-available/default and ensure that NameVirtualHost is set to *
NameVirtualHost *
which is default value anyway. This can be *:80 but whatever this is set to, all the other virtual hosts have to be set in the same way.
then create a new file at /etc/apache2/sites-available/your-site-name
and add
<VirtualHost *>
ServerName domain.of.site
DocumentRoot /path/to/sites/public/folder
</VirtualHost>
where the * is the same format as NameVirtualHost
save this and then enable the site using
sudo a2ensite your-site-name
Ok, we are done! Now use your favourate deploy method, such as capistrano to deploy to the path you specified in the virtual host. Remember that the path in the virtual host is pointing to the public folder in the rails app, so you would deploy to the parent folder of that path.
Enjoy! if there are any errors in this, let me know via a comment.




Nik Wakelin
Oliver Clarke