A WordPress Setup With Docker, PHP 7.4, Apache 2.4 and MySQL 8 on Ubuntu 20.04 LTS

Image for post
Image for post

Are you a web developer working on another WordPress site? If so, you may want to run a site locally and safely on your laptop to play around with a theme or plugin first, or you want to experiment with this or that cool feature with no fears on breaking the live site.

Today’s post is especially helpful in 2020 and 2021 with so many radical, disruptive changes taking place in the WordPress community mainly introduced by the development of Gutenberg, the new content editor for WordPress 5.0.

Gutenberg aims to be a game-changer in the way WP sites are built. Some argue it resembles Medium or Wix in the way content is created, but judging by the debate users have had so far, the future of the new editor’s adoption might not seem too clear yet.

Be that as it may, in today’s post let me guide you through the process of running a WordPress site locally with the help of a specific, custom Docker set up.

Prepare the Docker Environment

All you need to start off is a copy of the WordPress site you’re working on in the form of a ZIP file as well as a copy of its database as an SQL backup, then clone this GitHub repo:

Unzip your ZIP file into the wpdocker directory:

Create an .env file:

Make sure to comment out or remove the CREATE DATABASE statement, if any, from your SQL script and then copy it into docker/mysql/backup.sql

Build the Docker containers:

Image for post
Image for post

Import the Database Backup

With the Docker containers running already, SSH into wp_mysql to import the database backup:

Add a New Entry to Your Hosts File

Find out the IP address of your Apache container:

With the IP at hand, add the following entry to /etc/hosts:

As you can see my IP is 172.18.0.3 this time, but of course don’t forget to replace that one with your actual IP instead.

Edit Your WordPress Configuration File

Find out the IP of your MySQL container:

And update your wp-config.php file accordingly as follows:

Once again, as you can see my container’s IP is 172.18.0.4 this time, but don’t forget to replace that one with your actual IP instead.

Update the URLs

The URLs must be changed at this stage, which can be done in several different ways. Below it is shown how to do this directly in the database by running these two queries in the MySQL prompt.

Set up File Permissions

Finally set up permissions in order to enable the installation of new plugins, themes, and so on.

The step-by-step process described above worked for me on Ubuntu 20.04 LTS, and hopefully you’ll find something useful that can be applied to your particular set up and situation too! If you’re already familiar with Docker your site will be up and running in minutes.

In my opinion the present how to guide may definitely be a good alternative to installing WordPress 5 with other popular stacks like XAMPP, WAMP and MAMP, particularly if working as a part of a team.

Thanks so much for reading! For now that’s all I have to say about moving a live Gutenberg WordPress site from live to localhost. I hope you’ll stay tuned for the next episode about installing a self-signed SSL certificate to enable HTTPS.

You may also be interested in…

Written by

Hi there! How are you today? I blog about technology, the Internet, SEO, programming tips, PHP and more. programarivm.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store