Screencast - deploying - 2
In this screencast I’ll set up a Linux Ubuntu system on Slicehost sufficiently so that we can run a Rails app with the Mongrel server. Next time I’ll demonstrate how to extend this configuration by setting up Apache with Passenger (mod_rails), and possibly MySQL. This last configuration — Linux + Apache + Passenger + MySQL — is a baseline setup for a real web site that will perform adequately under modest load.
After setting up your system in the manner of the first deployment screencast, you will need to create a non-privileged user, make some changes to sudo (which allows for non-privileged users to conduct privileged “root” tasks) and /etc/sshd_config (so that your system is more secure), and finally, update the system software. Additionally, you will need to get the hostname set up right. These tasks are essentially the topic of http://wiki.slicehost.com/doku.php?id=get_started_with_your_new_ubuntu_slice and I’m not going to do them here. There are a lot of ways these steps can be messed up, so I would advise you to follow the instructions from your system provider scrupulously, or do it together with an experienced Linux person. These topics are “out of scope” for the main task of prepping your system for Rails. The one thing I would say is that you really do want have your Rails app in a directory owned by a non-privileged user, and avoid running everything as “root” as much as you can. In my interactions below, you will see that I don’t have to enter a password; that’s because I’m using ssh’s (or putty’s [a good Windows ssh client - http://www.chiark.greenend.org.uk/~sgtatham/putty/]) support for public/private key handling. It is entirely OK if you do all these steps but get prompted for a password. Don’t sweat the small stuff (if it works)! Another command I use is scp, which is like ssh but for secure file transfer. For ssh and scp, you can check the manual pages on Linux (man ssh and man scp) and Google for more advice — but, I’m afraid, these commands are out-of-scope for the screencast, where the focus is on Rails.
- First we will install app of the Linux packages we need to support Rails, build code from C (which is needed for some of the Ruby/Rails native extensions that come with Gems), Apache, and Sqlite3. Some of these instructions come from the link above; Sqlite3 is from http://wiki.slicehost.com/doku.php?id=5-minute_rails_install&s=sqlite. Also, we will need unzip. AS ROOT,
apt-get install build-essential zlib1g zlib1g-dev openssl ssl-cert libssl-dev ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby libsqlite3-0 libsqlite3-dev sqlite3 swig libsqlite3-ruby unzip
- After the Ruby install, we need to link the specific versions (e.g., ruby1.8) to names where we can access them as ruby, ri, irb, etc. AS ROOT,
sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb
- We will install RubyGems from source. AS ROOT,
mkdir sources; cd sources wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz tar zxvf rubygems-1.3.1.tgz cd rubygems-1.3.1 sudo ruby setup.rb cd ~ sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem sudo gem update --system
- Now comes Rails. Since we’re using the Gem system, this is almost exactly like what you did to set up your development machine. Notice that when we install Rails, we ask for a specific version; Rails 2.2.2 is out now, but our code runs on 2.1.1. (It should be safe to use the last 2.1 version, 2.1.2.) AS ROOT,
sudo gem install rails sudo gem install -v=2.1.1 rails sudo gem install mongrel sudo gem install sqlite3-ruby sudo gem install googlecharts
- I made a ZIP of MetricsMine with “rake package” — now I’ll move it over to the target system with scp, and will run it with Mongrel. Notice that when I run it, I want to run it as the root user so that the application can use port 80. Notice that the first steps are done as an ordinary user.
Oh, one more thing: Notice in the screencast that I’m starting Rails in “production” mode: This is new for us! Also notice that I copy my development.sqlite3 database to production.sqlite3 — that’s good enough to get us started.
blog comments powered by Disqus
Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment