Skip to content

Instantly share code, notes, and snippets.

@ojdon
Last active February 27, 2024 13:56
Show Gist options
  • Save ojdon/d6330cdccea41e4e298eb1a850391c8a to your computer and use it in GitHub Desktop.
Save ojdon/d6330cdccea41e4e298eb1a850391c8a to your computer and use it in GitHub Desktop.
Install WordPress via Command Line and run locally via Docker

Install WordPress via Command Line and run locally via Docker

This guide provides step-by-step instructions for installing a vanilla (clean) instance of WordPress using WP CLI and running it via Docker.

Requirements

Before proceeding with the installation, ensure that the following requirements are met:

Installation Steps

1. Install WordPress using WP CLI

  1. Open your terminal.
  2. Navigate to the directory where you want to install WordPress.
  3. Run the following command to download the latest version of WordPress:
    wp core download --path=wordpress
    
  4. Navigate into the WordPress directory:
    cd wordpress
    

2. Run WordPress via Docker

  1. Create a docker-compose.yml file in your project directory with the following content:

    version: '3'
    services:
      wordpress:
        image: wordpress:latest
        ports:
          - "8000:80"
        environment:
          WORDPRESS_DB_HOST: db
          WORDPRESS_DB_USER: your_database_user
          WORDPRESS_DB_PASSWORD: your_database_password
          WORDPRESS_DB_NAME: your_database_name
        volumes:
          - ./wordpress:/var/www/html
      db:
        image: mysql:5.7
        environment:
          MYSQL_DATABASE: your_database_name
          MYSQL_USER: your_database_user
          MYSQL_PASSWORD: your_database_password
          MYSQL_ROOT_PASSWORD: rootpass
        volumes:
          - ./mysql:/var/lib/mysql
  2. Run the following command to start the Docker containers:

    docker-compose up -d
    
  3. Once the containers are up and running, you can access your WordPress site by visiting http://localhost:8000 in your web browser.

That's it! Enjoy portably development your next WordPress website on any machine! 🥳🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment