Skip to content

Instantly share code, notes, and snippets.

@leigler
Last active June 13, 2019 09:42
Show Gist options
  • Save leigler/68ad653514925b72c38fb27b7c31e521 to your computer and use it in GitHub Desktop.
Save leigler/68ad653514925b72c38fb27b7c31e521 to your computer and use it in GitHub Desktop.

digital ocean wp + react build

install

  • wordpress 18.04 marketplace droplet
  • submit an ssh key ssh-keygen -t rsa
  • once droplet is created, create A record to point at the droplet's IP
  • ssh into ssh root@YOURIP to set root password/finish install
    • includes LetsEncrypt, for later SSL, run certbot --apache -d YOURDOMAIN.com -d www.YOURDOMAIN.com

git hook

Digital Ocean outlines how to set up a git hook here.

TL;DR:

  1. ssh into your droplet
  2. without changing directories:
  • sudo chown -R `whoami`:`id -gn` /var/www/html
  • then: mkdir ~/proj, cd ~/proj, git init --bare to create a bare git-dir
  • create/open your post-receive file: nano hooks/post-receive

inside:

#!/bin/bash
while read oldrev newrev ref
do
    if [[ $ref =~ .*/master$ ]];
    then
        echo "Master ref received.  Deploying master branch to production..."
        git --work-tree=/var/www/html/PATH/TO/THEDIRECTORY-YOU-WANT-TO-PUSH-TO --git-dir=/ROOT/proj checkout -f
    else
        echo "Ref $ref successfully received.  Doing nothing: only the master branch may be deployed on this server."
    fi
done

  • your PATH/TO/THEDIRECTORY-YOU-WANT-TO-PUSH-TO should be an empty directory
  • save and close this file, then run chmod +x hooks/post-receive to make script executable
  • logout of your ssh, and git remote add production ROOT@YOURIPADDRESS:proj.

Reference

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