Skip to content

Instantly share code, notes, and snippets.

@axelf
Forked from te-online/git-deployment-manual.md
Created January 30, 2017 12:17
Show Gist options
  • Save axelf/de4a9baca7caae03b6825bfcf7a51ae3 to your computer and use it in GitHub Desktop.
Save axelf/de4a9baca7caae03b6825bfcf7a51ae3 to your computer and use it in GitHub Desktop.
Git Deployment strategy set-up manual 👀 🚀

Steps

  1. Init local git repository (remember to create .gitginore with wp-config.php before staging anything)
  2. Configure SSH-key access to server with git [https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/, https://help.ubuntu.com/community/SSH/OpenSSH/Keys#Transfer_Client_Key_to_Host]
  3. Init a bare repo on the server git init && git config core.bare true
  4. Create a new post-receive hook with nano .git/hooks/post-receive (content see below!)
  5. Execute chmod 755 post-receive on the script
  6. Add remote to local repository git remote add staging user-name@your-domain.com:www/your-website
  7. Try pushing git push staging master
  8. Check if everything works as expected.
  9. Add a .htaccess to the .git directory with content: deny from all
  10. Repeat for all stages.

Gotchas

  • wp-config.php and .htaccess will be replaced although .gitignore is in place

Solution

Add the following (adjust folder- and filenames) to the post-receive hook

cp ~/www/config-files/wp-config-staging.php ../wp-config.php
cp ~/www/config-files/.htaccess-staging ../.htaccess

Create a directory outside the webroot with config files. (Consider settings debug = true for staging/testing).


  • Denying plugin/theme/update installation on live only works if owner of folder is different from php user.

Solution

If the users are different, do chmod 755 <folder> on plugins/themes/upgrade folder in live environment.


  • Charsets of mysql dump and live database is not compatible.

Solution

Change charset from utf8mb4 to utf8 in wp-config.php and export again.


Content of post-receive file

#!/bin/sh
GIT_WORK_TREE="../" git checkout -f

# optional, move config files
cp ~/www/config-files/wp-config-staging.php ../wp-config.php
cp ~/www/config-files/.htaccess-staging ../.htaccess

# optional, remove dev files
rm -rf ../node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment