DEV Community

Diego Carrasco Gubernatis
Diego Carrasco Gubernatis

Posted on • Originally published at diegocarrasco.com on

Quick and simple Local WordPress Setup for Lazy Developers

Quick and simple WordPress Setup for Lazy Developers

I needed a fast way to set up WordPress locally. I tried various methods, but they were either too complex or didn't work. So, I created a simple, lazy solution.

This is by no way secure, but it runs on the first try 😁

The code is in this GitHub repository. Feel free to use it.

How It Works

This setup revolves around 4 files:

1 docker-compose.yml :

This file:

  • Uses the latest official containers for WordPress, MariaDB, PHPMyAdmin, and WP-CLI.
  • Sets up a wordpress database with user and password root.
  • Launches a WordPress instance linked to the database.

2 setup.sh :

This script:

  • Detects whether you have docker-compose or docker compose and uses the correct one.
  • Sets your UID and GID in a .env file.
  • Generates an alias file for quick commands.

3 start.sh :

This script:

  • Creates the WordPress directory.
  • Sets permissions to 777 (yes, it's insecure).
  • Starts Docker Compose.

4 alias.sh :

Autogenerated by setup.sh or start.sh. Source it to get these aliases:

  • dc: Docker Compose commands.
  • wpcli: WP-CLI commands.
  • wpbackup: Backs up the database to ./backups.
  • wpdown: Backs up and then stops and removes containers and volumes.

How to Use

First you need to clone the repository:

git clone https://github.com/dacog/lazy-docker-compose-wordpress-setup.git
cd lazy-docker-compose-wordpress-setup

Enter fullscreen mode Exit fullscreen mode

Run these commands to get started:

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

Enter fullscreen mode Exit fullscreen mode

Now you are good to go. You will see a new folder wordpress is created in the path you were in.

Now you can:

You receive this information also when you run start.sh.

Using the Aliases

alias dc

  • Bring up the services:
dc up -d

Enter fullscreen mode Exit fullscreen mode
  • Stop the services:
dc down

Enter fullscreen mode Exit fullscreen mode
  • Stop and remove volumes:
dc down -v

Enter fullscreen mode Exit fullscreen mode
  • View the status of the services:
dc ps

Enter fullscreen mode Exit fullscreen mode

alias wpcli

Run WP-CLI as root (it includes --allow-root):

  • Check WordPress version:
wpcli core version

Enter fullscreen mode Exit fullscreen mode
  • Install a plugin:
wpcli plugin install hello-dolly --activate

Enter fullscreen mode Exit fullscreen mode
  • Update WordPress core:
wpcli core update

Enter fullscreen mode Exit fullscreen mode
  • Create a new post:
wpcli post create --post_title='My New Post' --post_content='This is the content of the post.' --post_status=publish

Enter fullscreen mode Exit fullscreen mode

wpbackup

Back up the database to ./backups:

wpbackup

Enter fullscreen mode Exit fullscreen mode

wpdown

Back up the database and files, then stop and remove everything:

wpdown

Enter fullscreen mode Exit fullscreen mode

Alternatives

Here are some other methods to consider:

  1. Local by Flywheel: User-friendly local WordPress setup with advanced features. To be fair, I completely forgot about this when I was trying to get WordPress to run locally. This is way more powerful, but you need many clicks... and you need to fill a form to download it.
  2. DevKinsta: Offers local development with easy deployment to Kinsta hosting. I haven't tried this one.

Top comments (0)