Last active
August 29, 2015 14:20
-
-
Save jteneycke/8940691ddb7db3077042 to your computer and use it in GitHub Desktop.
rails vps deployment without ripping your eyes out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 "your_email@example.com" | |
# test the connection so it adds the key to your authorized hosts list | |
ssh -T git@github.com | |
# add the phussion passenger package server key, and binaries source to to your apt packages list | |
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7 | |
echo 'deb https://oss-binaries.phusionpassenger.com/apt/passenger 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 | |
wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz | |
tar -xzf ruby-2.2.2.tar.gz | |
cd ruby-2.2.2 | |
./configure | |
make | |
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 | |
project_dir="my_app" | |
cat > /etc/apache2/sites-available/deploy.conf <<EOF | |
<VirtualHost *:80> | |
ServerName example.com | |
ServerAlias www.example.com | |
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 | |
</Directory> | |
</VirtualHost> | |
EOF | |
# disable the default apache2 page | |
a2dissite 000-default | |
# enable your new apache passenger site config | |
a2ensite deploy | |
service apache2 restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.