Most of this I got from the DigitalOcean file.
- Sign up for an account at digitalocean.com. Create a droplet using the pre-configed Ubuntu 12.10/Rails/Ngix/Unicorn option and using an ssh key if you set one up first. [An overview can be found here.] (https://www.digitalocean.com/community/articles/how-to-set-up-ssh-keys--2) If you don’t set up an SSH key, that's okay, DigitialOcean (DO) will send you one to your email.
- Once setup with an IP, point your domain or subdomain to the IP from wherever you are hosting as an A record. Log in using
ssh [email protected]
. Enter your password if needed. - Type
passwd
into the console to change the password of root to something you can remember. - If you want add a new user so you don’t have to use root then type
adduser [username]
in the console. Feel free to fill out the FullName part and just skip the rest. - Give that user sudo privileges by typing.
visudo
. Scroll down to privileges specification and copy the root line that saysroot ALL=(ALL:ALL) ALL
but change root to the new username you added. Once complete, save the file and try to ssh in to verify it worked correctly withssh [username]@ip.address.of.server
. It's recommended for security purposes to change the port of ssh and limit who can log in, but that's something you can Google if you want. - Update apt-get installer by running
apt-get update
. - Update your gems by running
gem update
. You also may want to update gem in general by typeinggem update --system
. - You can use the built in SFTP that DigitalOcean provides, but I prefer git. In order use git, you need to install it. Type
apt-get install git
. - Digital Ocean sets you up with a default rails program/root path at
/home/rails
. Rename or delete this folder so you can replace it with your content. By doing this you don't have to update any config paths in unicorn or nginx. From/home
typemv /rails /rails_old
You can then clone your project into the/home/rails
location as/rails
by typinggit clone [address of your repo] rails
. - Make sure your project uses rails 2.0.0 as that's the default DO has installed. Move into your rails app folder and run
bundle install
. If you are using mysql, you may need to install it on your local machine first in order to bundle and get your Gemfile.lock in order. You can't just run gem install mysql or else you get errors. To get it to work run brew install mysql then gem install mysql then bundle install in order to deploy. If you don't have homebrew installed it's and easy install by just googling for it. - If you are using mysql, add the password to your
database.yml
file for production. Your password is located as the welcome message when you log in. - Migrate your db to production by running
rake db:migrate RAILS_ENV=production
. - If you have seed data, seed your db running
rake db:seed RAILS_ENV=production
. - Precompile your assets by running
bundle exec rake assets:precompile RAILS_ENV=production
. - Restart unicorn by running
service unicorn restart
. - Your site now should be up and running on your droplet IP's address - http://ip.address.goes.here/ and by this time your domain should have populated so browse to it and see your site up.
$ service unicorn restart
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/configurator.rb:91:in
block in reload': directory for pid=/home/unicorn/pids/unicorn.pid not writable (ArgumentError) from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/configurator.rb:87:in
each'from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/configurator.rb:87:in
reload' from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/configurator.rb:68:in
initialize'from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:108:in
new' from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:108:in
initialize'from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/bin/unicorn:126:in
new' from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/bin/unicorn:126:in
<top (required)>'from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/unicorn:23:in
load' from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/unicorn:23:in
'from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in
eval' from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in
'master failed to start, check stderr log for details