Skip to content

Instantly share code, notes, and snippets.

@adambray
Created October 2, 2014 16:06
Show Gist options
  • Save adambray/55b98c89f814013c249b to your computer and use it in GitHub Desktop.
Save adambray/55b98c89f814013c249b to your computer and use it in GitHub Desktop.
# Notes from following: https://gorails.com/deploy/ubuntu/14.04
# Make sure we're in the home directory of our deploy user
cd /home/deploy
# Create the SSH Directory so we can log in without a password (using a key instead)
mkdir .ssh
cd .ssh/
# This is the file where SSH keeps keys you can log in with for this user
touch authorized_keys
# In this file, paste the public key from your OWN computer's .ssh folder
nano authorized_keys
# Update the list of software we can install, then install commonly needed tools to install ruby
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties
# Install rbenv, which helps us manage ruby
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
# Install ruby-build, a pugin for rbenv which helps us install new rubies
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
which ruby
# Install ruby 2.1.2
rbenv install 2.1.2
rbenv global 2.1.2
# Verify that it worked, we should see v2.1.2 and it should be in our home folder
ruby -v
which ruby
# Don't install documentation when we install gems (faster)
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install bundler
# Install Phusion's PGP key to verify packages
gpg --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
gpg --armor --export 561F9B9CAC40B2F7 | sudo apt-key add -
# Add HTTPS support to APT
sudo apt-get install apt-transport-https
# Add the passenger repository
sudo sh -c "echo 'deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main' >> /etc/apt/sources.list.d/passenger.list"
sudo chown root: /etc/apt/sources.list.d/passenger.list
sudo chmod 600 /etc/apt/sources.list.d/passenger.list
sudo apt-get update
# Install nginx and passenger
sudo apt-get install nginx-full passenger
sudo service nginx start
# Edit the nginx conf file to point it to passenger, and tell it which version
# of ruby to use
sudo nano /etc/nginx/nginx.conf
# restart nginx
sudo service nginx restart
# Install postgresql
sudo apt-get install postgresql postgresql-contrib libpq-dev
# Postgres authenticates us by our system username, so we need to switch users to the 'postgres' user
sudo su - postgres
# create a user called 'rails'
createuser --pwprompt
# exit from postgres user back to 'deploy' user
exit
# test that we can log into postgres as 'rails' user
psql -U rails
# add the nginx host, which tells nginx to pass requests onto a specific app
sudo nano /etc/nginx/sites-enabled/default
sudo service nginx restart
# look at our logs to see what went wrong
cd /var/log
ls
cd nginx
sudo su
cd -
sudo nano /etc/nginx/sites-enabled/default
sudo service nginx restart
# On our local machine, we've set up capistrano and used it to deploy (see guide)
cd /home/deploy/ham_radio/shared/
# capistrano doens't check in our database.yml (it has PWs) wso we have to create it here
cd config/
touch database.yml
nano database.yml
ls -la
nano database.yml
cd ..
# Create the database
RAILS_ENV=production bundle exec rake db:create
# migrate and seed our database
RAILS_ENV=production bundle exec rake db:create
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production bundle exec rake db:seed
# restart nginx one last time and we're done!
sudo service nginx restart
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment