Art Of Programming

musings by Dmytrii Nagirniak

Setting Up Ubuntu 11.04 Server for Rails With RVM

I had to set up the server (Ubuntu 11.04) for running couple of Rails apps and thought I could share the notes I’ve written while doing that. Any feedback and improvements are welcome.

apt-get update ; apt-get upgrade

# set timezone
dpkg-reconfigure tzdata

bash < <(curl -s

# update /etc/bash.bashrc

# -y to answer YES for questions
aptitude -y install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev

rvm install 1.9.2; rvm use 1.9.2 --default

# while ruby is being installed prepare nginx
cd /usr/src
tar -xf nginx-1.0.0.tar.gz
cd nginx-1.0.0

# Use one place for installation
rm -r /opt/ && ln -fs /usr/local /opt

gem update --system ; gem update
gem install bundler
#install imagemagic
apt-get -y install imagemagick

# proceed with passenger
apt-get -y install libcurl4-openssl-dev
gem install passenger
# additional otions:
# --prefix=/opt/nginx
# --with-http_gzip_static_module --with-http_stub_status_module --with-http_sub_module

# add nginx autostart script:
# verify the correct paths
cd /opt && \
wget -O && \
mv /opt/ /etc/init.d/nginx && \
chmod +x /etc/init.d/nginx && \
/usr/sbin/update-rc.d -f nginx defaults

# add to /opt/nginx/conf/nginx.conf
include /home/*/apps/*/current/nginx.conf;
/etc/init.d/nginx restart

# copy ssh keys (from local computer)
cat ~/.ssh/ | ssh "mkdir ~/.ssh ; cat - >> ~/.ssh/authorized_keys"

# change default ssh port from 22 to something to get rid of nasty attacks
vim /etc/ssh/sshd_config # change the port number
service ssh reload

#install firewall?? No need for now as only openning 80,443 ports
# apt-get install ufw

That should be enough for you to start using the server. In the future post I plan to describe my setup to make deploying new applications easier.


I've used this guide for 3 apps and it's worked great. However the step "use one place for installation" wipes everything out for some reason so I skip that part but otherwise thanks.