This is a quick and dirty walkthrough on how to integrate Rails with Apache2 in Ubuntu via Phusion Passenger. This guide provides setup instructions for a solution that includes:
Install All Required Packages from Apt
sudo apt-get install apache2 ruby irb ruby1.8-dev rdoc build-essential libopenssl-ruby apache2-prefork-dev libapr1-dev libaprutil1-dev mysql-server libmysql-ruby libmysqlclient-dev
Install RubyGems
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.6.tgz tar xvzf rubygems-1.3.6.tgz cd rubygems-1.3.6.tgz sudo ruby setup.rb sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
Install Required Gems
sudo gem install rails passenger mysql
Compile Passenger Apache2 Module
sudo /usr/bin/passenger-install-apache2-module
Configure Apache2
sudo vim /etc/apache2/mods-enabled/phusion.load
Add the following:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11 PassengerRuby /usr/bin/ruby1.8 RailsEnv development
Setup Test Virtual Host
sudo rm /etc/apache2/sites-enabled/000-default sudo vim /etc/apache2/sites-enabled/railstest
Add the following:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/testapp/public
</VirtualHost>
Restart Apache2
sudo /etc/init.d/apache2 restart
Setup Default MySQL Database
mysqladmin create testapp_development -u root -p
Setup Test Rails Application
cd /var/www sudo rm index.html rails testapp -d mysql cd testapp sudo vim config/database.yml
Put in your root MySQL username and password.
Test!
If you see something like the following then you were successful!
Hey i have Ubuntu 10 Server version, and i tried to configure it following this guide and i cant get the About your applications’s evnirenment to deploy, only if i use script/server i can deploy it.
Thanks for the tutorial. I have a few comments.
A very important missing element was creating a symbolic link to gems. Without this, typing gem into the control panel has no results.
sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem
As soon as I installed passenger, the version was 2.2.15 but the contents of phusion.load points to 2.2.11. When passenger upgrades in the future, this file will need to be rewritten to reflect the correct version of passenger.
The last thing is in the creation of the mysql db for testapp_develepment. The command line issue of mysql create testapp_development -u root -p, at least on my Ubuntu 10.04 system, does not prompt for the password. This leaves me needing to enter my password on the command line itself becoming part of the history where anyone can see it. It’s more secure to login to MySQL with mysql -u root -p which prompts for the password. Then from there, create the database.