This is a fairly simple docker container to facilitate development of WordPress plugins.
Mac users:
- Docker Desktop includes everything you need.
Otherwise install:
This will configure your host-file and create the necessary config files first. You will likely need to enter your sudo password as this will add local.wordpress.test to your hosts file.
This will create and start your containers. Your browser will automatically open with your WordPress environment.
You can always run ./clean.sh to delete all persistent data of your WordPresss environment and start again from scratch.
By default ./start.sh will start the basic wordpress container. Alternatively you can call ./start.sh $CONTAINER_NAMES to start other containers.
The following are available:
- basic-wordpress: The basic image that's started by default. Can be accessed via basic.wordpress.test.
- woocommerce-wordpress: A WooCommerce installation. Can be accessed via woocommerce.wordpress.test.
- multisite-wordpress: A multisite installation. Can be accessed via multisite.wordpress.test.
For example, calling ./start.sh woocommerce-wordpress will start only the WooCommerce container. Calling ./start.sh basic-wordpress multisite-wordpress will start both the basic WordPress and multisite containers.
If you need WordPress trunk, a beta or a release candidate, there are two ways of going about that:
- Switch using WP CLI:
Note that you'll have to repeat this daily if you want to be on the latest nightly. If you want to switch back, do, note the
/wp.sh core update --version=nightly
--forcebecause you're downgrading:/wp.sh core update --version=5.3 --force
- Install and use the WordPress beta tester plugin.
Simply clone, extract or download any plugins you want available in your environment into the plugins directory. They will be immediately visible inside your WordPress installation. Don't forget to activate them!
You can run ./wp.sh to run WP CLI commands. By default this will execute the command in the first running WordPress container ( created from this project ). However if the first argument is the name of a container it will specifically run in that container.
For example: ./wp.sh shell will run wp shell in the first active WordPress installation. ./wp.sh woocommerce-wordpress cache flush will run wp cache flush in the woocommerce-wordpresss installation.
The docker environments come preconfigured with WordPress debugging on. If you want to enable Yoast debugging specifically, you can add the parameter yoastdebug to your URL. This will trigger the yoast debugging constants and show debugging logs on sitemaps and pretty print json-ld and such.
This container is already preconfigured with XDebug. The only thing left to do is to configure your IDE and browser. See the following 2 headers.
If you are using PHPStorm follow these instructions:
- Open up
Preferences -> Languages & Frameworks -> PHP -> Servers - Click the
+icon - Name: Give it a recognizeable name or use the following Host.
- Host:
<domain name here>(default for this docker:basic.wordpress.test) - Port: 80
- File/Directory
plugins/<your-plugin-name>maps to the absoulte path/var/www/html/wp-content/plugins/<your-plugin-name>. - File/Directory
wordpressmaps to the absoulte path/var/www/html. - Apply
In PHPStorm you can also add the wordpress directory to provide full WordPress indexation.
If you are using VSCode simply copy/paste the following launch.json ( don't forget to edit <your-plugin-name ) which you can edit by running Debug: open launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html/wp-content/plugins/<your-plugin-name>": "${workspaceRoot}",
"/var/www/html": "${workspaceRoot}/../../wordpress",
},
}
]
}This assumes your plugin is the root of your opened VSCode project.
Also make sure you have the XDebug extension installed!
For Firefox you'll want to install the Firefox XDebug helper. For Chrome you'll want to install the Chrome XDebug helper.
Both of these do exactly the same. They add an icon to your URL bar where you can choose the XDebug settings for your request:
- Setting it to
Debugwill make PHP pause on any breakpoints you've configured in your IDE ( provided you're listening to Debug connections ). - Setting it to
Profilewill make PHP time every function call and output a cachegrind file. These will be located in thedata/xdebugdirectory.- These can be opened with a tool called KCachegrind / QCachegrind. On Mac you can install it using
brew install qcachegrind. On Linux you can usually install it usingsudo apt install kcachegrind.
- These can be opened with a tool called KCachegrind / QCachegrind. On Mac you can install it using
- Setting it to
Tracewill make PHP output a full trace of every function call. These will also be located in thedata/xdebugdirectory.- By default parameters and return values are not included in traces. You can change these settings by changing your
config/php.ini. For documentation on which values to change see the XDebug documentation. - For viewing these files with a GUI you could use xdebug-trace-tree. Cloning that project in the
wordpressdirectory and visitinghttp://local.wordpress.test/xdebug-trace-treeshould get you up and running.
- By default parameters and return values are not included in traces. You can change these settings by changing your
All database ports are forwarded to localhost to make them easily accessible from various tools. You'll want to enter the following configuration:
| Property | Value |
|---|---|
| Host | 127.0.0.1 |
| Username | wordpress |
| Password | wordpress |
| Database | wordpress |
The port differs based on the installation you're running.
| Site | Port |
|---|---|
| basic-wordpress | 1987 |
| woocommerce-wordpress | 1988 |
| multisite-wordpress | 1989 |
The first run after a make can fail. Quit all docker containers with docker-compose down and run bash start.sh again.
Issue: Yoast#11
Changing the domain name of the multisite in config.sh does not work yet and causes the main site to do a redirect to the domain multisite.wordpress.test. Change the variable DOMAIN_CURRENT_SITE in seeds/multisite-wordpress-seed.sh to the custom domain you use and restart docker.
Issue: Yoast#9