This repository provides a simple and lazy approach to setting up a local WordPress development environment using Docker Compose. With just one command, you can get a fully functional WordPress instance complete with WP-CLI, MariaDB, and PHPMyAdmin, along with autogenerated aliases for easy management. A second command allows you to source these aliases for convenience. This setup is intended solely for local development and is not secure for production use.
- I needed a quick way to get a WordPress instance up and running locally.
- I tried a few alternatives, nd they were all either too complicated or just didn't work when I followed the README, so here is my approach.
- I also wanted some quick commands for specific tasks, such as backup, wp-cli and docker compose.
This is my approach to solve this.
Warning: This approach is only for local dev. It is not secure, and you should not use it for Production anywhere. You have been warned.
chmod +x start.sh
chmod +x setup.sh
./start,sh
source ./alias.sh
There are 3 important files:
docker-compose.yml
: here is where everything happens. It basically does the following:- gets the latest versions of the official containers for WordPress, MariaDB, PHPMyAdmin and WP-CLI.
- creates a database with name
wordpress
, user and passwordroot
. - creates a WordPress instance with that database.
setup.sh
: this is mostly for comfort. It does the following:- checks if you have an old
docker-compose
or a newdocker compose
version and uses it. - sets UID and GID ENV Vars with yours, and adds them to the
.env
file.- I'm still playing with this. The idea was to use the same local UID and GID for the container, but if I do that the container cannot use the folder. I just defaulted to chmod 777.
- checks if you have an old
start.sh
: creates the directory for WordPress, sets permissions to 777 (I told you this is not secure) and starts docker compose.alias.sh
: this is autogenerated when you run eithersetup.sh
orstart.sh
. Then you cansource ./alias.sh
to get the following aliases:dc
for docker compose in the version that you havewpcli
for wp-cli commandswpbackup
to make a db dump to ./backupsẁpdown
to make a db dump and then a docker down -v to remove containers and volume after making a backup
chmod +x setup.sh
chmod +x start.sh
./start.sh
# Bring up the services
dc up -d
# Stop the services
dc down
# Stop the services and remove volumes
dc down -v
# View the status of the services
dc ps
NOTE: The alias has --allow-root
. This means you will run wp-cli as root.
# Check the WordPress version
wpcli core version
# Install a plugin
wpcli plugin install hello-dolly --activate
# Update WordPress core
wpcli core update
# Create a new post
wpcli post create --post_title='My New Post' --post_content='This is the content of the post.' --post_status=publish
You can check the available commands at https://developer.wordpress.org/cli/commands/
wpbackup
uses wpcli to create a database dump in ./backups
wpdown
makes a database dump in ./backups, then runs docker down -v to remove the containers and volumes.
If you don't need this anymore, just remove the containers and volumes, and remove the folders.
# this removes all the volumes and databases, but does not delete the files in ./wordpress
dc down -v