I setup a new VPS this weekend and decided to share my notes. My notes are from being logged in as root. If you’re logged in as another user, you’ll be typing sudo a lot. :)

Configure your locale 

locale -a
locale-gen en_US.UTF-8
update-locale LANG=en_US.UTF-8
update-locale LANGUAGE=en_US.UTF-8
exit
ssh zer1   #zer1 is my VPS added to ~/.ssh/config 
locale -a   #should have en_US.UTF-8 listed 
update-locale   #errors? 
# Set your time zonedpkg-reconfigure tzdata 
ntpdate ntp.ubuntu.com

Update Ubuntu

apt-get update && apt-get upgrade
Install dependenciesapt-get install build-essential libmagickcore-dev imagemagick libxml2-dev libxslt1-dev git-core libapr1-dev libssl-dev libmysqlclient15-dev libcurl4-openssl-dev curl libncurses5-dev libreadline5-dev libopenssl-ruby1.9

Install MySQL

apt-get install mysql-server libmysqlclient-dev libmysqlclient15-dev libmysql-ruby
mysql_secure_installation
Install latest Ruby from sourcewget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz
tar zxvf ruby-1.9.2-p290.tar.gz
cd ruby-1.9.2-p290.tar.gz
./configure
make
make install
which ruby
gem list
gem install passenger mysql bundler

Set default environment for Rails

echo "export RAILS_ENV=production" >> /etc/environment
Install Nginx and Passengerpassenger-install-nginx-module
curl -L https://raw.github.com/jnstq/rails-nginx-passenger-ubuntu/master/nginx/nginx > /etc/init.d/nginx
chmod +x /etc/init.d/nginx
update-rc.d nginx defaults
service nginx start

Configure Nginx

mkdir /opt/nginx/conf/sites-enabled
nano /opt/nginx/conf/nginx.conf
add this within the http { } block:
change default listen port to 8080
include /opt/nginx/conf/sites-enabled/*;
nano /opt/nginx/conf/sites-enabled/test
*note port 8080 for Varnish
server {    listen 8080;    server_name mywebsite.com;    root /home/deploy/test/public;    passenger_enabled on;}
service nginx restart

Add deploy user

adduser deploy
su deploy    #switches to deploy
ssh-keygen -t rsa -C “deploy@myserver”
cat ~/.ssh/id_rsa.pub
copy the output into your favorite Git hosting as an allowed key (Assembla, Github, etc)
on your development machine:
cat ~/.ssh/id_rsa.pub
on the server as deploy user:
nano ~/.ssh/authorized_keys
paste in your development machine’s public key
git clone [email protected]:myapp.git      #lets you add host as known_host
rm -rf myapp         
Create a MySQL user and databasemysql -u root -p
create database myapp_prod;
create user ‘mydbuser’@’localhost’ identified by ‘secret’;
grant all privileges on myapp_prod.* to ‘mydbuser’@’localhost’;

Install Varnish HTTP cache

apt-get install subversion autotools-dev automake1.9 libtool autoconf libncurses-dev xsltproc quilt debhelper
svn co http://varnish-cache.org/svn/tags/varnish-2.0.5
cd varnish-2.0.5/varnish-cache
dpkg-buildpackage
cd ..
dpkg -i libvarnish1_2.0.6-2_i386.deb
dpkg -i varnish_2.0.6-2_i386.deb
service varnish start
Configure Varnishnano /etc/varnish/default.vcl
Leave this at defaults, but now you know where it is :)
nano /etc/default/varnish
Comment out DAEMON_OPTS use the following instead:
DAEMON_OPTS=”-a :80 -f /etc/varnish/default.vcl -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G”
service varnish restart