KatPadi's Point

Adventures in Semi-Automatic WP Deployment

I am back to doing WP projects and it’s just now that I realize that I need to make things simpler.

Enter site deployment.

For me, deployment is the most tedious part of development. Coding is fun but I hate WP deployment mainly because it is such a pain in the ass. This is why I read, tweaked and came up with  a scheme that I now follow when deploying. So I use this process when I work in WP:

PS. I also asked around for help plus, of course, Mr. Google

The Assumptions

  • Git is installed both on your local & remote servers.
  • You have a git repository.
  • Your ssh keys are set up correctly.

The Process: In a Nutshell

  1. Set up git in your local machine.
  2. Set up git (bare repo) in your server machine.
  3. Configure the post-receive hook git stuff.

The Process: Not In a Nutshell 😛

Remote Server Stuff

In your remote server, mkdir in some place like /var/git_bare_repos and then do the following:

git clone –bare <your git url>
cd <name of bare repo>/hooks
vi post-receive
#put the text after this
#!/bin/sh
export GIT_WORK_TREE=<path to your web root live files>
git checkout -f
#And then make it executable
chmod +x post-receive

Local Machine Stuff

git remote add <any name you can say “prod” or something> <your ssh username>@<remote server host>:<path to your git bare repo>

Now, every after git add, commit and push to your repository (Github or Bitbucket) in your local machine, you can just:

git push prod

…and your live stuff will be updated!!!

Amazing? Well, not quite because this is still a a 2-way process. I don’t know how to make the post-update git web hook yet. I read somewhere that it can automatically update the live codes in your server by just pushing from your local machine to the git remote repository.

TL;DR

Local changes -> Commit to git -> Push to repo -> Push to server -> Live codes will be updated via post-receive hook

I know might be a better way to do this but for now this is my only solution.

Leave a Reply

Your email address will not be published. Required fields are marked *