wp-4-docker

A WordPress Development

Usage no npm install needed!

<script type="module">
  import wp4Docker from 'https://cdn.skypack.dev/wp-4-docker';
</script>

README

WP 4 Docker

This is a Docker based local environment for WordPress developing using the new WSL2.

Table of Content

  1. Overview
  2. Requirements
  3. Getting Started
  4. MySQL
  5. MailHog

Overview

WP 4 Docker is an easy and automate local development environment for WordPress that works on Linux, macOS, and Windows 10 Home ( Version 2004 ) for WSL2.

Requirements

Getting Started

Before you begin, I would like to point out one of the file that gets used often, and that file is custom.yml and when you docker up for the first time, it will then duplicate default.yml to custom.yml inside of the global folder and it will use that to generate any sites you want. By default, the only site that gets create is the dashboard and sandbox. You can manually copy the default.yml and copy to the .global folder and rename to custom.yml and start your process of creating your sites. up.

sites:
  sandbox:
    provision: true
    repo: https://github.com/benlumia007/wp-4-docker-sites.git
    host:
      - sandbox.test

Supressing prompts for elevating privileges

To allow vagrant to automatically update the hosts file without asking for a sudo password, add one of the following snippets to a new sudoers file include, i.e. sudo visudo -f /etc/sudoers.d/vagrant_hostsupdater.

For Ubuntu and most Linux environments:

Allow passwordless startup of Vagrant with vagrant-hostsupdater.

The most easiest way to achieve powerless sudo is to add your user to the sudoers with no password and it works with Linux and macOS

username ALL=(ALL:ALL) NOPASSWD:ALL

Windows: UAC Prompt

You can use cacls or icacls to grant your user account permanent write permission to the system's hosts file. You have to open an elevated command prompt; hold ❖ Win and press X, then choose "Command Prompt (Admin)"

cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G username:W

How to Begin

To begin, use git to clone the repository to anywhere

git clone https://github.com/benlumia007/wp-4-docker.git WordPress

I would like to keep this simple so I'm going to clone the repository to a folder called WordPress and navigate to the folder

cd WordPress

At this point, since all the volumes has been set already in the docker-compose.yml file, you don't need to do anything from here so to get started, please use the following command sudo npm -g install You should now have some few options especially the following wp4docker up, wp4docker start, wp4docker restart, wp4docker stop, and wp4docker down. Let's go ahead and do a wp4docker up, this will bring up the docker up, if you haven't pull the images, it will do that first and it will create nginx, mysql, and mailhog.

Before you begin, you should always wait for between 5 to 10 seconds everytime when you either start, restart, or up due to mysql container needs to finished initializing or else the the included provision will fail. After you have waited, let's begin,

wp4docker provision

This will provision setup, databases, dashboard, sites, resources, each will do their parts. After it finishes, make sure to restart the containers, but in reality, you should only need to restart the nginx container, all you need to do is wp4docker restart nginx, if you just do a wp4docker restart nginx, it will restart all three containers.

Please note for the sake of containers, you should not do wp4docker up or wp4docker down often, you should only use these if you need to change to a different container or something fail or screws up the containers. Mostly you should only use wp4docker start, wp4docker restart, or wp4docker stop as much as possible.

When you add new sites if necessary, just follow copy and paste one of the sites and modify it. Then you should do a wp4docker provision and wp4docker restart nginx.

Certificates and phpMyAdmin

In the custom.yml file, there is a section where you will see phpMyAdmin and TLS-CA, this is where any resources will go so that it will generated any resources that comes with. At this time, only phpMyAdmin and TLS-CA is included since the project itself will be using https rather than http for connection.

As for the certificates, it will generate a root ca and the rest for sites. You should only need to install the ca.crt and it should be SSL ready.

MySQL

By default, only the root is set, but the good thing is that when creating a WordPress site, it will then create a new user and password "wordpress" and it will then create a database if exists and will launched.

user = root
password = root

user = wordpress
passsword = wordpress

user = classicpress
passsword = classicpress

When you create a new site, it will use wordpress by default, you can use both root or wordpress to login.

MailHog

You can now access MailHog

WordPress

user = admin
password = password

ClassicPress

ClassicPress is now supported, to aactivate, use the following

sites:
  classicpress:
    provision: true
    repo: https://github.com/benlumia007/wp-4-docker-sites.git
    host:
      - classicpress.test
    custom:
      cms_type: ClassicPress
user = admin
password = password