Running a Rails app on a newly provisioned VM
  • This article assumes you're already connected to a VM that has rbenv, postgres, and caddy installed, and an /apps folder created.

  • Steps

    • Point the domain/subdomain that you want to use, to the ip address of the server (create an A record).

    • Connect to that newly created domain using the VS Code Remote SSH extension (assuming you have an authorised ssh key or password).

      1. ssh root@staging.mydomain.com
    • Pull your codebase down from Github into the apps folder. When prompted for credentials, don't enter your normal password. Instead, create a personal token here and enter it when prompted for a password.

      1. cd /apps
        git clone https://github.com/my_repo app_name
    • Copy over your environment variables

    • Run bundle install, rake db:create and rake db:migrate as usual

    • Add passenger to your Gemfile

      1. gem 'passenger'
        bundle install
    • Start a new daemonized server with passenger on port 1111 (use a different port if this VM already has other apps that are using that port)

      1. bundle exec passenger start --daemonize -p 1111
    • Configure caddy to forward your newly running app (on port 1111) to your subdomain (from step 1)

      1. Open up /etc/caddy/Caddyfile

      2. staging.mydomain.com {
          reverse_proxy localhost:1111
        }
      3. Restart caddy

      4. service caddy restart

  • Website Page