Docker development environment for Wordpress.
- Clone this repo to your project directory.
- Download a wordpress composer project to a subfolder called
wordpressand runcomposer install. The docker-compose config expects the document root to be found atwordpress/web, but you can change this to something else (such aswordpress/www) if your composer project uses a different folder name. - Run the following command to build and start the httpd server:
sudo USER_ID=$(id -u) GROUP_ID=$(id -g) docker-compose up httpd
USER_ID and GROUP_ID are used to recreate the container's user with the same user and group ID as the user on the host. This is important because it means that any new files created by PHP-FPM, wpcli or wordpress Console will be created as if they belong to the host user, not root.
For convenience, this command is included as a script called dockup, which you can move to a folder in your system's PATH. There is also a script called dockdn that simply calls sudo docker-compose down. By adding these scripts to your PATH, you can call them from anywhere in your project folder.
For convenience, a script called dockwpcli is included that runs sudo docker-compose run --rm wpcli, and takes care of setting USER_ID and GROUP_ID.
# Get the status of your site.
dockwpcli stThe XDebug config in etc/php/xdebug.ini is set to use VSCODE by default. To use a different editor, just change the IDE key.
If you want to enable logging, set XDEBUG_TRIGGER to 1 when you run the wpcli service.
Add this configuration to your project's .vscode/launch.json to listen for XDebug
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/wordpress": "${workspaceFolder}/wordpress"
}
}