Skip to content

Instantly share code, notes, and snippets.

@the-sanjar
Created May 23, 2019 05:17
Show Gist options
  • Save the-sanjar/7819159b07251914c6de68dfb56dbb19 to your computer and use it in GitHub Desktop.
Save the-sanjar/7819159b07251914c6de68dfb56dbb19 to your computer and use it in GitHub Desktop.
capistrano deploy

Capistrano Deploy (Nginx + Passenger) on Ubuntu 16.04+

Install

Ruby & Dependencies

# Install dependencies
sudo apt-get update
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 nodejs libsqlite3-dev sqlite3

# Install RVM
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash -s stable

# Install Ruby (for example 2.5.1)
rvm install 2.5.1

Then create a corresponding gemset with proper ruby version. Like for example: rvm use 2.5.1@gemset_name --create

PostgreSQL

# Install Postgres
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib

# Enter in postgres console
sudo -u postgres psql

# Set postgres user with password
alter role postgres with password <password>;

Passenger + Nginx

# Install GPG key and add HTTP support for APT
sudo apt-get install -y dirmngr gnupg
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates

# Add an APT repository
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update

# Install Passenger + Nginx
sudo apt-get install -y nginx-extras passenger

After Passenger + Nginx is installed, edit /etc/nginx/nginx.conf and uncomment include /etc/nginx/passenger.conf; if it's commented. If include /etc/nginx/passenger.conf; doesn't exist in the config, add it manually like in example:

http {
    include /etc/nginx/passenger.conf;
    ...
}

And then run sudo service nginx restart

Redis

To get the sidekiq work on server, it is required to install redis server

# Install redis-server
sudo apt-get install redis-server

# Make redis config to be used by default on system start
sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.default

Configure

Nginx

# Open Nginx config
sudo nano /etc/nginx/nginx.conf

# Add the following code in 'http' block
server {
    listen 80;
    server_name <server name or IP>;
    root /var/www/<app name>/current/public;
    passenger_enabled on;
}

# Then restart nginx
sudo service nginx restart

Postgres

In order to successfull deploy with Capistrano using postgres on the server side, the postgres config needs to be changed. Run sudo nano /etc/postgresql/9.X/main/pg_hba.conf, and change all the peer mods to md5.

System

In order to deploy with Capistrano, it is necessary to set the permissions for a system user (deployer).

sudo chown -R deployer:deployer /var/www/

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