Skip to content

Instantly share code, notes, and snippets.

@jcave
Last active February 12, 2016 01:52
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jcave/11363191 to your computer and use it in GitHub Desktop.
Save jcave/11363191 to your computer and use it in GitHub Desktop.
How to set up a DigitalOcean server with their 1-click Ubuntu/Rails/Ngnix/Unicorn/Mysql install

Basic Rails App on Digital Ocean / Ngnix / Unicorn

Most of this I got from the DigitalOcean file.

  1. 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.
  2. 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 root@ip.address.of.server. Enter your password if needed.
  3. Type passwd into the console to change the password of root to something you can remember.
  4. 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.
  5. Give that user sudo privileges by typing. visudo. Scroll down to privileges specification and copy the root line that says root 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 with ssh [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.
  6. Update apt-get installer by running apt-get update.
  7. Update your gems by running gem update. You also may want to update gem in general by typeing gem update --system.
  8. 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.
  9. 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 type mv /rails /rails_old You can then clone your project into the /home/rails location as /rails by typing git clone [address of your repo] rails.
  10. 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.
  11. 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.
  12. Migrate your db to production by running rake db:migrate RAILS_ENV=production.
  13. If you have seed data, seed your db running rake db:seed RAILS_ENV=production.
  14. Precompile your assets by running bundle exec rake assets:precompile RAILS_ENV=production.
  15. Restart unicorn by running service unicorn restart.
  16. 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.
@victorhazbun
Copy link

$ service unicorn restart

  • Restarting Unicorn web server unicorn start-stop-daemon: warning: failed to kill 7453: Operation not permitted
    /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:ineach'
    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:ininitialize'
    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:ininitialize'
    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

@jcave
Copy link
Author

jcave commented Sep 4, 2014

No clue why that would be happening =/

@mer10z
Copy link

mer10z commented Nov 22, 2014

I had to create a swapfile to get gem update to work on a small droplet: https://meta.discourse.org/t/create-a-swapfile-for-your-linux-server/13880

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment