A starter docker environment for building and testing WordPress Plugins and Themes against different versions of WordPress and PHP
Setup up a full docker compose stack
./setup-all.sh
You can optionally request a specific version of WordPress and PHP by providing the relevant docker image tag.
./setup-all.sh 6.5-php8.3
For example 6.5-php8.3
will give us an image with WordPress 6.5 and php 8.3 if we want to test those specific versions.
-
Source environment variables
source envs/dev.env
-
Ensure user and group permission in container match host user and group to side step entre world of file permission pain.
./build.sh
The version of PHP and WordPress can optionally be controlled via the
$WORDPRESS_TAG
variable (Default:6.4-php8.3
) on both the script and the Dockerfile. -
Install any additional 3rd party plugins and themes
./install-deps.sh
-
(Optional) Attempt to automatically discover any *.sql files and import them into the database.
./import-data.sh
-
Start the dev environment
docker compose up
Service | URL |
---|---|
WordPress | http://localhost:8080 |
phpMyAdmin | http://localhost:8081 |
MySQL | mysql://db:3306 or mysql://localhost:3306 |
Any valid theme or plugin located in ./themes/
or ./plugins/
will be available in the site.
A theme or plugin under development can be git cloned
into ./theme
or ./plugin
respectively and worked on in place.
E.g.
git clone git@github.com:johnsmith/my-theme.git themes/my-theme
Any theme or plugin in ./themes or ./plugins are 'installed' and available for use in wordpress.
WordPress Packagist is a project to utilise composer to programatically manage and install wordpress plugins.
Wordpress plugins and themes available via Wordpress Packagist can be required and installed via composer.
composer require wpackagist-plugin/woocommerce
More information on WordPress Packagist
Custom scripted installation of additional themes and plugins can be added to install-deps.sh
.
The install-deps.sh
script will also call the composer install
command for us to install any packages listed in our composer.json
Firstly, source the database credentials.
source envs/dev.env
We can which variables are set with the env
command
env | grep DB_
Connect as WordPress system db user
docker compose exec db mysql -u $DB_USERNAME -p$DB_PASSWORD $DB_NAME
Connect as root user
docker compose exec db mysql -u root -p$DB_ROOT_PASSWORD
If the database container is running we can export with
docker compose exec db mysqldump -u root -p$DB_ROOT_PASSWORD --all-databases > dump.sql
docker compose exec -T db mysql -u root -p$DB_ROOT_PASSWORD $DB_NAME < dump.sql
Or the ./import-data.sh
helper script will search our repo for a *.sql
file and import it into the database for us.
./import-data.sh
docker compose down -v