How can I deploy a Rails app to a VPS (virtual private server) or a dedicated server? It would be nice to have an easy to follow guide.
I know about scripts to automate the process, but I think it's better to have everything under control, in order to understand better the process.
I have successfully deployed a heavy Rails application to Linode or Digital Ocean, using these technologies:
These are the steps that work for me:
Setting up the virtual machine
Create a new virtual machine
Follow the setup instructions of your hosting, being Linode or Digital Ocean, to create the node and set it up.
Set up date
Update packages
Security
Create user
Set up SSH key-authentication
On local:
On the server:
Set up SSH
Set up firewall
Set up fail2ban
Set up if you have enough free memory, as it tends to eat it.
Setup Ruby
Install Git
Install rbenv
Install Ruby
Setup servers
Install nginx + Passenger
Install PostgreSQL
Setup libraries
Install node.js
Needed to pre-compile assets.
Install bundler
Setup the application
Create the user in PostgreSQL
Deploy the code * On the server: * sudo mkdir -p /srv/yoursite.com * sudo chown deploy:deploy /srv/yoursite.com * On your dev machine: * bundle exec cap production deploy:check (it will throw an error because it doesn't find the database) * On the server: * cd /srv/yoursite.com/shared/config * vim database.yml (paste your database config) * vim secrets.yml (paste your secrets config) * On your dev machine: * bundle exec cap production deploy * bundle exec cap production whenever:update_crontab
Configure logrotate
I deployed my rails application to my production servers (it's a cluster) with Capistrano before, but I found that Capistrano is a bit complex and sometimes even became trouble maker... So I wrote my deployment script by bash shell script.
I have put it on github with a brief guide: deploy_rails