First, install these packages using apt-get or aptitude:
- ruby
- rubygems
- ruby1.8-dev
- build-essential
- apache2-mpm-prefork
- apache2-prefork-dev
Add the following line to /etc/bash.bashrc
export PATH=$PATH:/var/lib/gems/1.8/bin
Install mod_rails (passenger) using gem:
gem update
gem install passenger
Run passenger-install-apache2-module to checks for prerequisites and build the necessary modules. It’s important to note the highlighted output that begins with LoadModule, because we’ll be pasting that directly into an apache configuration file later. If you let the info get away from you, it’s fine to run the install again.
Now it’s time to configure the server. I prefer not to touch the original configuration files, so I create the file /etc/apache2/conf.d/passenger.conf with the information provided by passenger-install-apache2-module. The contents are similar to this:
# DON'T USE THIS. USE THE OUTPUT FROM passenger-install-apache2-module ON YOUR SERVER
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-2.0.3
PassengerRuby /usr/bin/ruby1.8
Finally, we need a virtual host configuration for you application. Put this in /etc/apache2/sites-available/sitename. This is very close to the sample provided by passenger-install-apache2-module, but I’ve added the rewrite rule that allows ‘cap deploy:web:[dis|en]able’ to operate.
<VirtualHost *:80>
ServerName www.yourhost.com
DocumentRoot /somewhere/public
RewriteEngine On
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
</VirtualHost>
Run the commands a2dissite default and a2ensite sitename to turn the site on, and a2enmod rewrite to turn on the rewrite module. Once you restart apache, your application should Just Workâ˘.