Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Wordpress DEV environment with docker compose

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.

My context

  • 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.

TLDR

chmod +x start.sh
chmod +x setup.sh
./start,sh
source ./alias.sh

How does this work

There are 3 important files:

  1. 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 password root.
    • creates a WordPress instance with that database.
  2. setup.sh: this is mostly for comfort. It does the following:
    • checks if you have an old docker-compose or a new docker 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.
  3. start.sh: creates the directory for WordPress, sets permissions to 777 (I told you this is not secure) and starts docker compose.
  4. alias.sh: this is autogenerated when you run either setup.sh or start.sh. Then you can source ./alias.sh to get the following aliases:
    • dc for docker compose in the version that you have
    • wpcli for wp-cli commands
    • wpbackup 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

How to use

chmod +x setup.sh
chmod +x start.sh
./start.sh

How to use the aliases

alias dc

# 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

alias wp-cli

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/

alias wpbackup

wpbackup uses wpcli to create a database dump in ./backups

wpdown

wpdown makes a database dump in ./backups, then runs docker down -v to remove the containers and volumes.

Uninstall/ Remove

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 

About

Set up a local WordPress development environment easily with Docker Compose using this repository. One command sets up WordPress with WP-CLI, MariaDB, and PHPMyAdmin, plus autogenerated aliases for quick management. A second command sources these aliases. Perfect for quick, lazy local development. Not secure for production use.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages