-
Setting up Hardy for Ruby on Rails Hosting
These instructions should take you through the process of setting up Ubuntu Server version 8.04 (Hardy Heron) for Ruby on Rails hosting using Apache and Passenger Phusion (mod_rails). This will also step you through adding certain programs needed to install the Rmagick gem required to add Captcha to a RoR application and the mysql gem.
Install the server with just the SSH server option so you can copy and paste the commands for simplicity
So once you have the base installed, make sure your distribution is up to date:
sudo apt-get update sudo apt-get dist-upgrade
Install the package required for building software, siince we will be doing some compiling:
sudo apt-get install build-essential
Install Ruby and Mysql:sudo apt-get install ruby ri rdoc mysql-server libmysql-ruby ruby1.8-dev irb1.8 libdbd-mysql-perl libdbi-perl libmysql-ruby1.8 libmysqlclient15off libnet-daemon-perl libplrpc-perl libreadline-ruby1.8 libruby1.8 mysql-client-5.0 mysql-common mysql-server-5.0 rdoc1.8 ri1.8 ruby1.8 irb libopenssl-ruby libopenssl-ruby1.8 psmisc
Download the latest rubygems, we like to build this so that we have the latest version since the package repositories for Ubuntu have an older version:
wget https://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz tar -xzvf rubygems-1.3.1.tgz sudo ruby setup.rb
Make sure the symbolic links are all set. If you have to type gem1.8 list (instead of just gem list) then the link is not working:
sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb
Now install rails:
sudo gem install rails
Since we are using Apache, we may as well set that up now before we start installing the other gems we need:
sudo apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapr1 libaprutil1 libmagic1 libpcre3 libpq5 openssl
Now in order to use Captcha we need to install ImageMagick before the Rmagick gem, do the following:
Remove old imagemagick package:sudo apt-get remove imagemagick
Remove old graphicsmagick:
sudo apt-get remove graphicsmagick
Install build dependencies for ImageMagick:
sudo apt-get build-dep imagemagick
Make sure you have everything else you will need:
sudo apt-get install libperl-dev gcc libjpeg62-dev libbz2-dev libtiff4-dev libwmf-dev libz-dev libpng12-dev libx11-dev libxt-dev libxext-dev libxml2-dev libfreetype6-dev liblcms1-dev libexif-dev perl libjasper-dev libltdl3-dev graphviz gs-gpl pkg-config
Download ImageMagick, extract it and switch to it (your version may vary):
sudo wget ftp://ftp.fifi.org/pub/ImageMagick/ImageMagick-6.4.8-5.tar.gz
sudo tar xvzf ImageMagick-6.4.8-5.tar.gz
cd ImageMagick-6.4.8-5/ sudo ./configure --disable-openmp sudo make sudo make install
To confirm it all worked and see available formats, run the following:
identify -list format
We had to execute and add the following to the .bashrc file in order to get it working after an error with the above:
export LD_LIBRARY_PATH=/usr/local/lib
Now rmagick will install without a hitch:
sudo gem install rmagick
To install the Mysql gem to improve Mysql performance. You need to get the proper headers to install the gem:
sudo apt-get install libmysqlclient-dev sudo gem install mysql --no-rdoc --no-ri
Installing Paasenger Phusion is a snap, just do the following:
sudo gem install passenger
Run the following to install the module:
passenger-install-apache2-module
You will need to modify your Apache configuration, if you installed it via the above method, do the following:
sudo nano /etc/apache2/apache2.conf
Add the following at the bottom of the apache2.conf:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6 PassengerRuby /usr/bin/ruby1.8
Write the virtual host file for your application, make sure the DocumentRoot points to the public folder of your application:
sudo nano /etc/apache2/sites-available/domain.com.conf
Paste the following into the configuration file:
<VirtualHost *:80> ServerAdmin root@localhost DocumentRoot /route/to/applicationfolder/public/ ServerName www.domainname.com ServerAlias domainname.com </VirtualHost>
By default it will load the production settings in the database.yml, this can be modified in the VirtualHost file if you want to use a different environment add RAILS_ENV=enviroment to the VirtualHost file.
Before you can run your application, you need to enable the site:sudo a2ensite domain.com.conf /
Copy your code to the location you specified in the DocumentRoot, make and rake the database, then restart apache:
sudo /etc/init.d/apache2 restart
One important step you need to know of is to make sure the application is owned by the apache process, if not then you will receive permission errors. To give ownership of the application to the apache user:
sudo chown -R www-data\: /path/to/applicationfolder
If all went well, you now are hosting your own RoR application.
Leave a reply