Creating a Local Copy for Peace of Mind
I’ve been there myself. You spin up a WordPress site on a WordPress managed host and let it run. Great up until something just stops working and you can’t access your admin section. You wish that you had a local working copy of the website, and even better, a backup running elsewhere to quickly point your DNS to.
There are many ways that you can do this but I’ll show you a simple approach that gets you setup quickly. This article assumes that you have a WordPress site running somewhere and Docker running on your machine.
Setting up your Local Environment
Create a folder on your machine and cd
into it with your terminal. I called it my app name. Execute the following command from within your newly created folder:
docker run -i -t -p "80:80" -v ${PWD}/app:/app -v ${PWD}/mysql:/var/lib/mysql mattrayner/lamp:latest
This sets up the Docker environment for Apache
, MySql
, PHP
, and phpMyAdmin
. Read more about the Docker environment here.
The command also creates the app
and mysql
folders. The app
folder is where your WordPress is going to go into and the mysql
folder keeps your database data persistent. Otherwise, each time that you close a docker connection, your data will be gone too.
Open your Docker dashboard and you’ll see your container running. Click on it and then click on the CLI button to get into your container. Just type in mysql
to access your mysql server and then create your wordpress
database.
# mysql
mysql> create database wordpress;
That’s it. Local Environment Setup.
Backing Up Your WordPress
My favorite tool for this is the Duplicator
plugin. Install Duplicator
by going to your Plugins and search for Duplicator. Activate the plugin once it’s installed.
Click on the Duplicator
button in the sidebar and then click on the Create New
button.
Go through the prompts to generate an Installer
and an Archive
. You’ll see a couple of status messages: Good
and Notice
. Click Yes. Continue to the Build Process
if everything looks good and then click on the Build
button.
Download both files.
Installing Locally
Copy the downloaded files into your app
folder that was generated earlier: this includes both the installer.php
file and the archived zip.
Visit 0.0.0.0/installer.php
. It might be 127.0.0.1/installer.php
or localhost/install.php
on your machine. You’ll see the Duplicator
installer.
The database will be your wordpress
database that we created earlier. The User is root
and the Password is blank. Click Validate and you’ll see that everything should pass.
Action: Empty Database
Host: localhost
Database: wordpress
User: root
Password:
Accept the terms and notices and click Next
.
Wait for everything to extract.
Click on Admin Login and use your same Username and Password that you used on your Production Environment. You should see the following message.
Type in 0.0.0.0
in your browser and see that your website was successfully installed locally.