For about the 5th time in the past 3 months, I’m in the process of setting up another deployment server to host my web apps and it’s starting to get that repetitive feeling. Every time, I think I should take notes and then everytime I forget to, so here goes.
In case you’re wondering, I’m certainly not the first to do this, so I turned to the steadfast wisdom of Lord Google ™ and read through a few articles. This post is my own concoction, but many chunks of it will feel familiar having read through the resources below.
Hopefully you were expecting that. There’s plenty of choices, but I’ve used Amazon, Digital Ocean and now Rackspace. If you’re really keen, you could always build it yourself, but I don’t have that time on my hands.
Spec-wise, it’s really up to you, and you’ll obviously need to think about who’s using the server, but here’s my preference:
I also have a couple of commands I run every time I setup a server, because nano is the bane of my existence:
Now the server’s up and running- or you’re still fiddling with a graphics card- let’s get a user for our deployments. You can use the root user, but that’s a bit dodgy. So let’s setup that user:
Now edit /etc/sudoers:
And add your ssh key:
From here on, I’m just going to assume you’re logged in as the new deploy user.
Finally, make sure your server is up to date, and sort out time zones so you don’t have to work out what was happening at 3am later on:
In case you didn’t know- and because I didn’t- Nginx is actually a proxy server (which makes it a bit different to Apache). This is what makes it perfect for our use, we’ll setup Nginx to proxy requests to our unicorn workers.
You can edit /etc/nginx/nginx.conf if you want, but mine tends to stay pretty standard:
There’s a whole thing out there about http://rvm.io/ and http://rbenv.org/ and which runs faster, jumps higher and all the rest, but I prefer to stay out of inane internet arguments for my own sanity. Right now, I’m preferring Rbenv, because it feels easier and lighter, but both are awesome, so go with your gut.
First we install rbenv and a bunch of dependencies:
There’s a step in there that rbenv will tell you to do, but I seem to forget it all the time. Edit ~/.bash_profile:
Then reload your environment:
Now that rbenv is ready to go, install a ruby version (2.2.0 for me as of now) and bundler, because it’s awesome:
It appears I got a little distracted here and forgot to update. This will be updated- soon, I hope.
Edit (2015-07-31): Ok, so it looks like this isn’t getting updated. I’ll guess we’ll find out how to do it next time I have to setup a Ruby-Rails-Unicorn-Nginx-Mina stack. That’s my bad.
I’ve always used Capistrano as my deployment tool (other than the dark ages of FTP) but I really like the look of Mina, so I’m giving it a try.
First, add the mina gems:
Then set it up:
Then all it takes is a single command:
Who am I? I'm Maddison Joyce. I've worked in all areas of software development and before that I was in tech support. I love writing code, learning new technologies, reading books and talking to people. I can help you with your next software project.
© Maddison Joyce, 2014.