I’m currently developing my WordPress locally, committing my code to GitHub with Git and then SSHing into my server and doing a “git pull” to update my code. Is this a good option for code deployment onto a WordPress site (I obviously have root level access to my server in this case.) I know of things like Capistrano, but would that be overkill for deployment to a WordPress site? How can I make the most of Git/GitHub in this case?
I use git for this and find it works really well. A few suggestions:
- Add your uploads directory (wp-content/uploads) directory to your
- Run a web server and database server on your development system so you can test changes locally before pushing them to production.
- Keep your database connection settings consistent beween dev and prod, or add wp-config.php to your
.gitignorefile to prevent your development wordpress settings overwriting your production ones.
- Avoid updating plugins on your production system using the admin interface of Wordpress – as at best, your git copy will overwrite any plugins you update as soon as you push/checkout, at worst you’ll get conflicts. Do your updates using the the admin interface on your development system, commit, push and checkout in production.
Consider adding a git
post-receivehook to checkout your updates automatically into the directory you use to publish wordpress via your web server (e.g.
/var/www). This allows you to only check out the files themselves, avoiding any git metadata finding it’s way into your web server’s document root, and also means you can add any permission changes into the post-receive hook so your permissions stay consistent every time. An example is included below:
#!/bin/sh unset GIT_INDEX_FILE # the directory your web server serves wordpress from export GIT_WORK_TREE=/var/www/example.com/ # the local directory where your remote git repository sites export GIT_DIR=/home/git/repos/example.com.git/ # below user is for debain - you want the user and group your webserver uses sudo git checkout -f sudo chown -R www-data:www-data $GIT_WORK_TREE sudo chmod -R 755 $GIT_WORK_TREE sudo chmod 600 $GIT_WORK_TREE/wp-config.php sudo chmod -R 775 $GIT_WORK_TREE/wp-content