by dontangg on April 4, 2012
Configure the server
Get a server with Ubuntu
With Rackspace Cloud Servers, this is very easy. Login to Rackspace, choose Cloud Servers under Hosting, click Add Server, and choose your OS. I chose Ubuntu 11.10 (Oneiric Ocelot). In just a minute, you’ll have an IP address and root credentials that you can use for ssh.
I did everything using ssh. If you’ve never done this, Google it and learn the best way to do it on your platform.
When you first get your server, it is pretty bare. Let’s get some stuff installed. First, you’ll want to update apt-get so that it installs the latest versions of everything:
$ apt-get update
Then, upgrade all the currently installed packages (-y means say yes to all prompts):
$ apt-get upgrade -y
Now, we’ll install new stuff:
$ apt-get install git-core, build-essentials, curl, zlib1g-dev, \
libxml2-dev, libxslt1-dev, openssl, nodejs, postgresql, libpq-dev, \
git pull command to update the code on the server. Everything else is a pretty fundamental need.
Since I used rbenv and ruby-build for ruby, I didn’t install any ruby package here. Instead, I just made sure that all ruby’s dependencies were installed.
$ apt-get build-dep ruby1.9.3
Create a new user
Now, we need to create a user for our app to run as. I called mine
$ useradd -m -g staff app_user
The -m option will create the new user’s home directory (/home/app_user). The -g option tells it which group to add the user to (staff).
Set your new user’s password.
$ passwd app_user
To allow app_user to execute commands with super-user privileges, you need to add him to the sudoers file located at /etc/sudoers.
app_user ALL=(ALL) ALL
Now you’re set to log out as root and log back in as app_user. If I specify any commands that it says you don’t have rights to access, just put
sudo in front of the command, enter app_user’s password and it will let you.
I really like rbenv. These steps are mostly copied from its homepage, but slightly simplified for my use case.
Clone rbenv into ~/.rbenv.
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility.
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
Add rbenv init to your shell to enable shims and autocompletion.
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
Restart your shell so the path changes take effect. You can now begin using rbenv.
$ exec $SHELL
Now, we’ll install ruby-build that makes it really simple to install ruby.
$ mkdir -p ~/.rbenv/plugins
$ cd ~/.rbenv/plugins
$ git clone git://github.com/sstephenson/ruby-build.git
$ rbenv install 1.9.3-p125
Set the global version of ruby to 1.9.3.
$ rbenv global 1.9.3-p125
Rebuild the shim binaries. You should do this any time you install a new Ruby binary (for example, when installing a new Ruby version, or when installing a gem that provides a binary).
$ rbenv rehash
We’re done installing ruby. Let’s add some reasonable defaults for installing ruby gems.
gem: --no-ri --no-rdoc
Now let’s just install a couple ruby gems that will allow us to use capistrano later.
$ gem install rake
$ gem install bundler
$ rbenv rehash