Docker environment with WordPress, PHP-FPM, Apache, phpMyAdmin and MariaDB
Use it to develop your plugin or to have a LAMP stack to test some code.
Feel free to use as you wish.
-
Clone the repository on your local machine or WSL.
-
Generate self-signed SSL certificates with
mkcert
.- Run:
docker run -ti --rm -v "$(pwd):/certs" alpine/mkcert -cert-file /certs/wordpress.local.pem -key-file /certs/wordpress.local.key.pem wordpress.local localhost 127.0.0.1 ::1
- Filename for the key must be wordpress.local.key.pem.
- Filename for the cert must be wordpress.local.pem.
- Otherwise, you'll need to change the 000-default.conf.
- Run:
-
Trust the certificate in the host machine.
- On Mac,
- Press Cmd + Space and type Keychain Access, then hit Enter to open it.
- Drag and drop the .pem certificate file into the Keychain Access window.
- Double click the dropped file and trust it with "Always Trust".
- On Windows, double click the certificate file and install it.
- On Mac,
-
Move the generated
.pem
to the path/.docker/wordpress/apache/certs
-
Run
docker compose up --build -d
-
Lastly, you'll need to add
127.0.0.1 wordpress.local
to your operating system's hosts file. See this tutorial to learn how to access them for Linux and Windows. Usually itssudo nano /etc/hosts
.-
In Windows, add the two following lines. For Linux, just the first one:
127.0.0.1 wordpress.local ::1 wordpress.local
-
-
Open wordpress.local in your browser.
-
Open localhost:8080 to access phpMyAdmin in your browser.
Command to run in wp-plugins for both host user and Docker be allowed to edit the files/folders:
sudo chgrp -R www-data wp-plugins/
sudo find wp-plugins/ -type d -exec chmod 0775 {} \;
sudo find wp-plugins/ -type f -exec chmod 0775 {} \;
mariadb
- stores the mariadb data. So, you can rundocker compose down
and the database will still be safe here. You may delete/mariadb/data/*
manually to reset the database./wordpress
- stores settings for the WP service./wp-logs
- stores the Apache logs from the WP service./wp-plugins
- it's where you put your plugins. Also, any plugins installed from WordPress will be present here./wp-themes
- it's where you put your themes. Themes intalled from WordPress will be present here too.
./.docker/wordpress/php/php.ini
: https://github.com/php/php-src/blob/master/php.ini-development