How to create on-demand environments for WordPress
“Spin up on-demand staging environment to test out your custom plugins and themes for WordPress”
Setting up a staging environment and maintaining it for every theme/plugin project for WordPress can be very daunting. Quite often when website developers work on design implementations or content creators try to add articles to their website, they tend to seek approval from team members more often than one can imagine. This can be a tedious amount of work and also time consuming if the team is limited by availability of staging environments.
Dockup helps you mitigate this problem by providing on-demand staging environments for you WordPress site. Your changes would automatically be made available across your team as and when you update it, while letting you concentrate on the design or the article.
In this article, we’ll see how you can use Dockup to automatically spin up on-demand copies of your WordPress site.
How can Dockup help?
Dockup can automatically spin up a staging environment every time you open a PR for your WordPress site. This way, you will have an environment ready at your disposal, with all the changes from the PR. All you have to do is, push code, test your changes for the theme, and perhaps show it your team.
You can also deploy your branches manually on Dockup. This can be super useful when a non-tech team member wants to test how the site looks for any commit or branch. Let’s see how to set this up.
Setting up Dockup
Assuming you have prior knowledge on how/where themes and plugins fits in WordPress, let me quickly setup a sample plugin for the sake of this documentation. If you don’t have any current project, tag along the next step to have a simple source code which we can deploy on Dockup to test things.
This plugin for WordPress will append a line to each of the post that we create. This can be used to write some thanks message or a goodbye message to the end of each post.
Setup the project folder as below:
- We have a root project folder called “ending-line-wp-plugin”
- A file with the plugin code, “ending-line-wp-plugin/ending-line/ending-line.php”
- Dockerfile for building images for Dockup
Copy paste the following code in the
Now let’s dockerise this one. Its pretty straightforward here. All you have to do is copy this one project folder in to a plugins folder inside the “wp-content”.
FROM wordpress:php7.3-apacheWORKDIR /var/www/htmlCOPY ending-line/ wp-content/plugins/ending-line/
Note that we are not using any scripts to start a MySQL server before we run the actual WordPress server. Dockup lets us spin up both containers separately and we will connect them using the environment variables.
Let’s create a Dockup Blueprint for this project and see how we can stage our plugin project.
We will need two containers here:
- The GitHub source using which we will build image.
Make sure that you have set the env variables for the database container. Refer the ones below for a start
Note that we are using GitHub as the source here, but you can also use a pre-built docker image of the plugin/theme you are developing.
Also, double check the env variables that your project might need. For this one, we need three. To know what env variables are supported by WordPress, head over here
Some important env variables are:
In case you are wondering what the DOCKUP_SERVICE is, please read more about Environment Variable Substitution available in Dockup.
Looks good, let’s try deploying this environment.
Now, you have a staging environment ready for you to test the plugin you just wrote!
Don’t forget to activate your plugin from the admin panel of WordPress. If you are following this sample app, remember to add the text to be appended to every post via
Settings > Ending Line Plugin
Want Dockup on-demand environments for your WordPress sites? Click here to get started.