As my WordPress plugin development process was quite flawed (Write code locally => upload via FTP => test on server => repeat :’D) I had to search for a better solution for being able to local develop plugins and test them.
I used this awful process before as I did not want to install all required software for running WordPress (Apache, MySQL, PHP) on my local machine as I like it being clean and only having services running I really need at that certain moment.
The better sysadmins of you would claim that I still could easily start/stop the services for only having them running when I am developing…but boy that still sounds like a way to big hassle for me.
And as you always do this nowadays: Docker for the rescue 😉
After researching and working my way to build a docker-compose file I now can say: This time this approach worked like a charm.
It now only is docker-compose up
and WordPress is running. I can live edit the files of my plugins, and they are loaded and used instantly.
docker-compose.yml
I assume you know about docker and docker-compose, if not give this article a read.
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: rootpw
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8080:80"
restart: always
volumes:
- ../mastodon_wordpress_autopost/autopost-to-mastodon/trunk:/var/www/html/wp-content/plugins/autopost-to-mastodon:ro
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
After executing docker-compose up
in the directory of the docker-compose.yml
all the services are started up and you are greeted with a WordPress installer on localhost:8080
(as I mapped the WordPress port to 8080
).
Click trough the WordPress installer and you got a working instance running.
Via the volumes
section you can map outside directories into the installation.
E.g. The following config maps my local developer directory ../mastodon_wordpress_autopost/autopost-to-mastodon/trunk
(which I have open in my editor) into the plugins directory of WordPress.
volumes:
- ../mastodon_wordpress_autopost/autopost-to-mastodon/trunk:/var/www/html/wp-content/plugins/autopost-to-mastodon:ro
You can map as many directories as you want. Keep in mind that the path is relative to the location of the docker-compose.yml
After activating the plugin in the WordPress GUI the plugin is up and running and I can live edit at in my editor. As it is mapped and not copied into the docker container all changes are reflected live.
Feedback? Questions? Corrections? [email protected]