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
My advice would be to use Bitbucket as it’s free and allows unlimited private repositories.
Requirement 2. Deployment service
There 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 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
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
Step 6. Create a project for deployment
After your account is successfully setup and verified, login and create a new project.
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.
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.
- 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.
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.
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!