Rails on Ubuntu 10.04: Passenger, Nginx, MySQL, Varnish
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?
- dpkg-reconfigure tzdata
- ntpdate ntp.ubuntu.com
- apt-get update && apt-get upgrade
- apt-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
- apt-get install mysql-server libmysqlclient-dev libmysqlclient15-dev libmysql-ruby
- mysql_secure_installation
- wget 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
- nano /etc/environment
- add the following line to it:
- export RAILS_ENV=production
- passenger-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
- 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
| server { listen 8080; server_name mywebsite.com; root /home/deploy/test/public; passenger_enabled on; } |
- service nginx restart
- 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 git@git.assembla.com:myapp.git #lets you add host as known_host
- rm -rf myapp
- mysql -u root -p
- create database myapp_prod;
- create user 'mydbuser'@'localhost' identified by 'secret';
- grant all privileges on myapp_prod.* to 'mydbuser'@'localhost';
- 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
- nano /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