Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
rails vps deployment without ripping your eyes out
# create a deploy user, and add them to sudoers
adduser deploy
gpasswd -a deploy sudo
# generate a key so you can just pop it on your github and pull your repo down from there
ssh-keygen -t rsa -C ""
# test the connection so it adds the key to your authorized hosts list
ssh -T
# add the phussion passenger package server key, and binaries source to to your apt packages list
apt-key adv --keyserver --recv-keys 561F9B9CAC40B2F7
echo 'deb trusty main' > /etc/apt/sources.list.d/passenger.list
chown root: /etc/apt/sources.list.d/passenger.list
chmod 600 /etc/apt/sources.list.d/passenger.list
# update your packages list so you've got all the latest dependency lists
sudo apt-get update
# install all of the stuff neccessary to build ruby, rails, and install postgres, apache2, and passenger
sudo apt-get install build-essential libssl-dev libyaml-dev libreadline-dev openssl curl git-core zlib1g-dev bison libxml2-dev libxslt1-dev libcurl4-openssl-dev libsqlite3-dev postgresql-9.3 libpq-dev apache2 libapache2-mod-passenger -y
# can probably get this script down to like 5 minutes if you use a ppa for the latest ruby
tar -xzf ruby-2.2.2.tar.gz
cd ruby-2.2.2
make install
# enable apache2 passenger module
a2enmod passenger
service apache2 restart
# make damn sure that we're using our freshly added ruby and not the old system one
# (might not have to do this if you go the ppa route)
rm /usr/bin/ruby
ln -s /usr/local/bin/ruby /usr/bin/ruby
# git clone down your project into the deploy users home directory
# eg. /home/deploy/my_app
# apache2 config points to the public folder in your app
# eg. /home/deploy/my_app/public
cat > /etc/apache2/sites-available/deploy.conf <<EOF
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/deploy/$project_dir/public
RailsEnv production
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
<Directory "/home/deploy/$project_dir/public">
Options FollowSymLinks
Require all granted
# disable the default apache2 page
a2dissite 000-default
# enable your new apache passenger site config
a2ensite deploy
service apache2 restart

This comment has been minimized.

Copy link
Owner Author

jteneycke commented May 11, 2015

If you have issues, you're gonna wanna check your logs/production.log and /var/logs/apache2/error.log to find out the situation you're in.

Also, there are some irritating rails secret setting of environmental variables to take care of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.