Install Wordpress Docker locally

WordPress is a popular Content Management System (CMS) that is used to create websites and blogs. Docker is a popular containerization platform that allows developers to easily create, deploy, and run applications in a containerized environment. In this guide, we will walk you through the steps of installing WordPress Docker locally on your computer.

Step 1: Install Docker

The first step is to install Docker on your computer. Docker provides installation packages for Windows, Mac, and Linux, which can be downloaded from their official website. Once the installation is complete, you can verify that Docker is installed correctly by running the following command in your terminal or command prompt:

docker --version

Step 2: Download WordPress

Download Wordpress from Wordpress.org and unzip. Edit your wp-config.php like this:

// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'MyWordPressDatabaseName' );

/** Database username */
define( 'DB_USER', 'MyWordPressUser' );

/** Database password */
define( 'DB_PASSWORD', 'Pa$$5w0rD' );

/** Database hostname */
define( 'DB_HOST', 'mysql:3306' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

Step 3: Create Docker Compose .yml file

In the unzipped folder, place this docker-compose.yml next to your wp-config.php

version: '3'

services:
  web:
    image: wordpress:latest
    depends_on:
      - mysql
    environment:
      WORDPRESS_DB_HOST: mysql:3306
      WORDPRESS_DB_USER: MyWordPressUser
      WORDPRESS_DB_PASSWORD: Pa$$5w0rD
      WORDPRESS_DB_NAME: MyWordPressDatabaseName
    ports:
      - "8000:80"

  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: MyR00tMySQLPa$$5w0rD
      MYSQL_DATABASE: MyWordPressDatabaseName
      MYSQL_USER: MyWordPressUser
      MYSQL_PASSWORD: Pa$$5w0rD

Step 4: Run Docker Compose

Open your terminal and navigate to your Wordpress folder, then run:

docker-compose up -d

Step 4: Setup Wordpress

Goto http://localhost:8000/wp-admin/install.php and setup Wordpress.

Conclusion

In this guide, we have shown you how to install WordPress Docker locally on your computer. Docker makes it easy to create, deploy, and run applications in a containerized environment, which can be very useful for developers. With Docker, you can quickly set up a WordPress site for testing and development purposes.