Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Server Setup

Finn Woelm edited this page Apr 23, 2018 · 5 revisions

~~ Work in Progress ~~

  1. Spin up a server at DigitalOcean

  2. Set up your firewall

  3. Set up non-root user

  4. Set up PostgreSQL database

  5. Modify /etc/postgres.../pga_hba.conf file to allow MD5 authentication

  6. Set up a database and database user

  7. Install libpq-dev (needed for gem 'pg')

     $ sudo apt-get install libpq-dev
    
  8. Install NodeJS as JS runtime

     $ sudo apt-get install nodejs
    
  9. Install CMake (needed for Rugged2: Git repository management)

     $ sudo add-apt-repository ppa:george-edison55/cmake-3.x
     $ sudo apt-get update
     $ sudo apt-get install cmake
    
  10. Set up Nginx, rvm, and Rails up to step 6

  11. Deploy environment variables

     $ cap production figaro_yml:setup
    
  12. Install cerbot and get SSL certificates (may need temporary Nginx configuration for acme-challenge)

     $ sudo add-apt-repository ppa:certbot/certbot
     $ sudo apt-get update
     $ sudo apt-get install certbot
     $ sudo certbot certonly -a webroot --webroot-path /var/apps/openly/shared/public -d <domain-name>
    
  13. Update Diffie-Hellman Parameters

     $ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
    
  14. Set up certbot auto renewal

  15. Now continue Set up Nginx, rvm, and Rails up with step 7

  16. Confirm that your site is live!

  17. Confirm that your SSL Rating is A+

FAQ

Error during cap production deploy: Cannot create extension "citext"

Are you getting the following error when running your Capistrano deployment?

PG::InsufficientPrivilege: ERROR:  permission denied to create extension "citext"
HINT:  Must be superuser to create this extension.
: CREATE EXTENSION IF NOT EXISTS "citext"

You will need to temporarily make your database user a superuser.

  1. Connect to the server: $ ssh user@server

  2. Connect to PostgreSQL as the superuser (not your database user):

    $ sudo su postgres
    $ \psql
    
  3. Make your database user a superuser: $ alter role your_user superuser;

  4. Run cap production deploy from your local machine. This time it should succeed

  5. Remove superuser from your database user: $ alter role your_user nosuperuser;

  6. Leave PostgreSQL shell: $ \q

How can I set up Puma to automatically start (autostart) on (after) reboot?

If you're using systemctl / systemd (e.g. Ubuntu 16.04):

  1. Add a puma service to the /etc/systemd/system directory:

     $ cd /etc/systemd/system
     $ sudo nano puma.service
    
  2. Copy the contents from this gist into the puma.service file. See gist comments for modification instructions.

  3. Verify the new service. There should be no output.

    $ sudo systemd-analyze verify puma.service
    
  4. Enable the service (so that it will be run on reboot)

    $ sudo systemctl enable puma.service
    
  5. Verify that the status is enabled

    $ sudo systemctl is-enabled puma.service
    
  6. Reboot and verify that puma auto restarts! (Be patient, it might take half a minute)

If you are using Upstart:

Take a look at this article: http://codepany.com/blog/rails-5-puma-capistrano-nginx-jungle-upstart/