WordPress Deployment with Deploy, Git and Bitbucket

WordPress-Deployment-with-Deploy-Git-and-Bitbucket

In recent years, developers have used WordPress for more powerful and complex sites.

As WordPress sites have become more complex, developers have required better tools. It’s not common to version control and to have multiple deployment environments for production, staging or testing.

In this tutorial, we’re going to show you one way to manage and deploy WordPress sites professionally. We’re going to use Bitbucket, Deploy and Git to deploy a WordPress site.

The 3 key tools for professional deployment

Requirement 1. Remote repositories

Bitbucket LogoTo make automated deployment possible, your repository (code/website) needs to be on a server accessible over the internet. You could setup your own or use GitHub or Bitbucket.

My advice would be to use Bitbucket as it’s free and allows unlimited private repositories.

Requirement 2. Deployment service

deployhqThere are many ways to automate deployment of your website. Few of the most used are Capistrano, Jenkins, Beanstalk and Deploy. Deploy is a hosted service and due to its price and simplicity is the one, I would recommend. Deploy allows you to set up all types of manual and automatic deployment for your sites. It supports Git, Mercurial and Subversion code repositories.

Requirement 3: Version control

git-logoGit is a distributed source control system. It allows teams to work together and manage multiple versions of a software from a single repository (codebase). Even if you are working alone, managing your code with version control system offers more convenience and is an efficient way of managing your code. It also makes it possible to push your code to external code hosting or sharing sites such as GitHub or Bitbucket. If you are already using version control and have an account with GitHub or Bitbucket, then you are few steps closer to achieving faster and easier deployment.

So, for the purposes of this article, we’re going to use Bitbucket, Deploy and a Git repository (containing our WordPress site) to manage our production website.

The 10 steps to professional deployment

Step 1. Install Git version control

Install Git if you haven’t already done so. If you are a command line user and familiar with Git commands proceed to next step else you could also download and install TortoiseGit or SourceTree. Both would allow you access to Git commands in a friendly manner without needing to use command line.

Step 2. Convert your local WordPress into a Git repository

After completing the first step, create a local repository to store your project files. You can use an existing folder or create a new one. Windows users using Tortoise Git could simply right click on your WordPress project folder and click on the option “Git create repository here…”

Step 3. Create a repository

Create an account on Bitbucket or GitHub and then set it up as a remote repository to which you can push your local code.

Step 4. Commit and push local repository to the remote one

After setting up everything, commit your code and push to the remote repository. This set is important, as when you proceed towards setting up DeployHQ with your repository, Bitbucket does not allow selection of an empty repository.

Step 5. Create an account with Deploy

Visit www.deployhq.com and create a free account.
git-deployhq-01.png

Step 6. Create a project for deployment

After your account is successfully setup and verified, login and create a new project.

git-deployhq-02.png

Step 7. Enter your login details

Next enter the login information of your code hosting repository such as GitHub or Bitbucket and then click on the “Check credentials and choose repository” button.

If the information provided is accurate, you would be displayed a list of repository in your GitHub/Bitbucket account. Choose the one which you had created in step 3.

git-deployhq-03.png

Step 8. Configure the deployment server

After selecting your repository, you would be displayed a form to enter your first server details for deployment. Some of the details you would need to fill are:

  • Name:
 The name of the destination server, e.g. My WordPress Site
  • Protocol:
 Choose from one of these protocol SSH / SFTP, FTP, Amazon S3 and Rackspace Cloud files. Most commonly SSH/SFTP would be the option. Go ahead and select it after which more form fields would be displayed to enter more information about your server.
  • Hostname:E.g. sftp.mywebsite.com. You can also add the server IP address.
  • Port
:
 Enter the correct port if it’s not the default 22.
  • Username
  • Password
  • Use SSH keys instead of Password
:
 This is a safer option but requires additional steps.
  • Path on server
:
 Make sure to add the correct path depending on whether you are deploying your entire WordPress site or just a custom theme.
  • Notification Email
:
 Enter an email where you would like to receive notification after every deployments.
  • Branch to deploy from
:
 The branch you would like to deploy from, and should be left as it is if you are using your master branch.
  • Environment:A way to name this server environment such as production, testing, etc.
  • Subdirectory to deploy from:Again this is as important as the “path on server” field. If you wish to deploy your entire repository then leave it blank or else enter the correct path.

If the details provided are accurate, you have now successfully setup your server (deployment location) with DeployHQ.

Step 9. Perform a test deploy

Before activating auto deployment, we need to ensure everything is working right and if you have set correct paths.

Click on the large green button labelled “Deploy Now”. After selecting the revisions/commit; at the next screen you could initiate the deployment or simply preview it. Click on “Run deployment” and test. If things go well, you are now just one step closer to setting up automated deployment.

git-deployhq-04.png

Step 10. Activate automated deployment

Setting up automated deployment will avoid the need to visit Deploy site every single time. To set it up:

  • First go to the “Servers & Groups” page which can be accessed via the “Settings” menu.
  • Click on the “pencil” icon which denotes “Edit” to go to the edit screen of the server you had setup earlier for deployment.
  • In the “Deploy Hook” box on the right mark the “On” option for auto deploy. Also make sure to copy the URL displayed in the “Deploy Hook” book. This would be used with your GitHub or Bitbucket repository to initiate automated deployments whenever you commit/push your local files to those repositories.
  • For Bitbucket hosted repository, visit the official guide to learn about setting up the hook we retrieved from DeployHQ.
  • For GitHub hosted repository, simply go to the repository page and then click on “Settings”. On the “Settings” page click on “Webhooks & Services” tabs and then click on the “Configure Services” button. You now have to find the “DeployHQ” option in the list of services and click on it. A form would be displayed where you could paste the deploy hook URL. Make sure to also mark the “Active” checkbox and then click on “Update Settings” button.
git-deployhq-05.png

After following the above steps, your automated deployment process would be complete and in future to update your site, you could simply commit your local changes and then push those changes to the remote repository.

Things to consider

Keeping your wp-config.php or any other file containing passwords inside a remote repository would be unwise. You would therefore have to ignore certain files in your local repository to avoid pushing them to the repository (GitHub / Bitbucket).

Deploy allows the option to create this file automatically and save its information with them, but the best method would be to manually uploading file the first time on your website.

If you require more information feel free to leave a comment. Happy Deploying!

Author

  • Steve Burge

    Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.

0 0 votes
Article Rating
Subscribe
Notify of
16 Comments
Oldest
Newest
Inline Feedbacks
View all comments
newtonsongbird
newtonsongbird
10 years ago

Thanks for this post. I’ve been working on this myself. One thing that would be helpful to cover would be that this process works with the files in your project but not the database – which for WordPress means any changes to menus, widgets, and the like. These need to be handled separately, and I’m still trying to determine the best way to handle those changes: WP Migrate DB Pro vs widgets that export each specifically?

Shannon Hubbell
Shannon Hubbell
10 years ago
Reply to  newtonsongbird

Yeah, agreed. The database is always the biggest stumbling block with deploying WP, and I was hoping to see something addressing that here.
(Not to knock the post, mind you. This was very useful.)

steve
steve
10 years ago

Thanks guys. That is a great idea for a follow-up topic.
Yes, the database management is far tougher than the file management.

Joe
Joe
3 years ago
Reply to  steve

This is a good plugin for that: WP Migrate DB

harishchouhan
10 years ago
Reply to  newtonsongbird

I use WP Migrate Pro myself as it now also support images. Another way would be to export local database, do a search and replace, and after uploading it, some MySQL command can be run. I had tried few such methods in the past but they caused more issues. WP Migrate Pro seems best at this particular task,

Julien Klepatch
Julien Klepatch
9 years ago
Reply to  newtonsongbird

I would recommend using the Duplicator Plugin. It handles both files and database migration, it works well, its fast, AND its free.

Kampiamo DiKuesto
Kampiamo DiKuesto
9 years ago

i try it but it is incompatible with my shared hosting limit:(

Taylor
Taylor
10 years ago

Cool post. I was wondering about the database as well. Me and a buddy (we live in 2 different countries) are working on a little wordpress project. Would it be ideal to share the files on bitbucket, then auto deploy them, using a fresh wordpress install and a fresh database? This is just for testing purposes. Just a little confused on the database part.

Martin McNeela
Martin McNeela
9 years ago

Thanks for the post, this helped me out a lot. I think there needs to more process overviews like this on the web rather that in-depth tutorials about small aspects of a process.
I have set my site up to go through [url=http://deployhp.com]deployhp.com[/url] to a [url=http://staging.mydomain.com]staging.mydomain.com[/url]. Do you know if there are is a way to use this to deploy to my live site (not automatically)? or is the best way to SSH into my server and pull the bitbucket repo?

Kampiamo DiKuesto
Kampiamo DiKuesto
9 years ago

DB deploy? and does this workflow require ssh access on hosting?

Laura Jit
Laura Jit
8 years ago

In the past, videos were considered a luxury, especially for small businesses with a limited marketing budget. This is no longer the case in today’s digital world.
Jay

Stubner

ManuelBS
ManuelBS
8 years ago

I’m not a wordpress developer but I know pretty well how we solve this problem in Drupal. Initially there was a so called “exportable API” and a module called features. This features module renderes the configuration settings from the database into files which makes the configuration deployable. Isn’t there a similar option in wordpress?

I just found [url=http://wptavern.com/wp-cfm-a-free-plugin-for-storing-and-deploying-wordpress-database-configurations]http://wptavern.com/wp-cfm-…[/url] may be this is a solution?

Lukasz Czulak
Lukasz Czulak
8 years ago

Hi, I use [url=https://buddy.works/]https://buddy.works/[/url] for deploy automatical to remote server only database manually deploy. Great stuff!

jaimin
jaimin
7 years ago

Hi Steve,
I want to make repository system for all my team and complete deployment and working system on server only.let me explain my scenario.
for e.g. [url=http://xyz.com]xyz.com[/url] is project and there is 3 people working on this project.
name of the team.
David – Back-end Developer

Monty – Front-end Developer

James – Back-end Developer
I don’t want to use local PC for them they have access of SFTP/FTP for their server repository and by using command they can deploy their assigned task to bit-bucket and I can deploy their task on development/staging repository as well as on live repository.
If possible I want to use source tree for them.
Is it possible?
If yes can you please write details blog for this?
Thanks,

Jaimin

Nick
7 years ago
Reply to  jaimin

Hi and welcome, Jaimin!
If you become a member at OSTraining, we can help you with this. You can view our affordable memberships at [url=https://wordpress.org/plugins/backupwordpress/]https://wordpress.org/plugi…[/url]

Laura
Laura
6 years ago

Great post! Thanks for sharing, Steve. I love using Bitbucket for WordPress because besides the amazing features just rattled off, there are a number of other reasons why I prefer it. One of the major challenges that so many developers face is the question of keeping code in sync while working collaboratively, so one great solution can be indeed Bitbucket. Here’s an article https://goo.gl/L1UZGF that states additional tips for using Bitbucket, your feedback would be much appreciated.

16
0
Would love your thoughts, please comment.x
()
x