This repository creates a development environment in Docker to develop a website in Wordpress multisite. Do not use in production or public URLs, use in https://localhost only.
It uses Debian 11 “bullseye” as the basis, which is a common server distro. Read the Dockerfile for more information.
For simplicity it uses a single container for the PHP server and MySQL. This will also allow you to run different containers and different databases for different git feature branches if you want. Or revert to a previously exported database state.
Start docker (in a Mac use the command bellow):
open -a Docker
Normally you'll need to do this just once:
cd /path/to/this/repository
docker build -t wordpressmultisite .
It will take a while to download the files if it's not cached.
Create the docker container. You don't need to do this often...
Don't forget to edit your own binds (-v) in the command bellow:
docker run -t -d \
-v $HOME/websites/mysite/wp-content:/var/www/html/wp-content \
-v $HOME/websites/mysite/import-export:/import-export \
-p 443:443 \
--name mysite wordpressmultisite
The wp-content
folder is where themes, plugins and all will be developed.
The import-export
folder will be used to import the MySQL database dump from an existing site to this development container.
Alternatively you can separate the uploads folder in the host with this container setting:
docker run -t -d \
-v $HOME/websites/mysite2/wp-content:/var/www/html/wp-content \
-v $HOME/websites/mysite2/uploads:/var/www/html/wp-content/uploads \
-v $HOME/websites/mysite2/import-export:/import-export \
-p 443:443 \
--name mysite wordpressmultisite
This might be useful to make it easier to rsync to update the images.
List running containers, start, stop and remove containers:
docker ps
docker start mysite
docker stop mysite
docker rm mysite
To login the container:
docker exec -ti mysite bash
Start nginx, mariadb and php:
./servers_start.sh
If you are binding /var/www/html/wp-content
folder to an empty folder in your host machine you may want to restore the default wp-content
with:
./default_wp-content.sh
Now you can visit your website home page:
Please note it uses a self-signed https certificate, so you'll need to accept the browser's exception the first time. In Firefox and Safari this is very straightforward. Just follow the interactive instructions on screen.
In Chome-based browsers you must go to localhost, inspect with the developer tools, open the console and paste the following command:
sendCommand(SecurityInterstitialCommandId.CMD_PROCEED)
- Wordpress admin
- Username:
admin
- Password:
va34raDFR64gbjkU
- PhpMyAdmin
- Username:
generic
- Password:
gfvcry35y@ehG1209
First download a dump of your production site database into your $HOME/websites/mysite/import-export
folder (in your computer).
Then, in your container shell, replace references bellow to your real domain/subdomain and database sql file.
Update the container database with the database from the site:
./import_wordpress_db.sh yourdomain.org yoursite_wordpress_db.sql
This will update yourdomain.org references in the database to localhost
. If your site URL includes the www, then you should add it to the command above.
Snapshots allow you to save the database state at any moment. And revert to that state latter.
To export a snapshot of the database at any moment:
./export_wordpress_db.sh snapshot_database.sql
The file snapshot_database.sql
will be saved in the host machine in the $HOME/websites/mysite/import-export
folder.
To import this snapshot latter:
./import_wordpress_db.sh localhost snapshot_database.sql
Now you can develop themes or plugins using your own computer tools inside the wp-content
folder.
cd ~/websites/mysite/wp-content
- It will be created a Wordpress
debug.log
file insidewp-content
- The access and error logs can be obtained in the container shell with
tail
,cat
ormore
, like for example:
tail -f /var/log/nginx/access.log
tail -f /var/log/nginx/error.log