Local development environment for WordPress with Docker && Docker Compose
⚠️ still work in progress ⚠️
Local development setup for WordPress using Docker && Docker Compose with Nginx - PHP-FPM - MySql - PHP MyAdmin - Mailhog - Self-Signed SSL Certificates
We should set our enviornment variables and generate our self-signed ssl certificates. If you don’t want to enable ssl certificates please comment or remove the follwoing code to avoid errors. docker-compose.yml
lines: 13 and 18 - etc/config/nginx.conf
lines: 83 to the end of file
We adjust the variables in .env to suite our project the default ports are:
# Clone the repository
git clone git@github.com:samk-dev/docker-wp.git
# Navigate to docker-wp
cd docker-wp
# Rename .env-example to .env
mv .env-example .env
## Generate Self-Signed SSL Certificate ##
## This is not required if you don't need https and you did comment/remove the ssl settings ##
# Give excution permissions to the script
chmod u+x chmod u+x etc/scripts/self-signed-init.sh
# Execute the script
./etc/scripts/self-signed-init.sh localhost
from the project root run docker-compose up -d
this will build and run the containers. Prepare yourself a ☕️ because it will take some time
From any web browser access:
The variables refrenced in the examples are the values you set in .env @ project root
When running docker-compose up
the first install will already fill the db credentials for you, so if you want to modify change the wp-config settings
When installing WordPress set the email as: dev@mailhog.local
/** MySQL settings - You can get this info from your web host **/
/** The name of the database for WordPress */
define( 'DB_NAME', $MYSQL_DATABASE );
/** MySQL database username */
define( 'DB_USER', $MYSQL_ROOT_USER );
/** MySQL database password */
define( 'DB_PASSWORD', $MYSQL_ROOT_PASSWORD );
/** MySQL hostname */
define( 'DB_HOST', '<container_name>:<container_port>' );
/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
You can access any container shell by using the command docker exec -it ${CONTAINER_NAME} sh
and exit
to exit
Example by installing Sage 10 Starter Theme by the guys @ root.io:
# Access WP container
docker exec -it docker-wp-dev sh
# Navigate to wp-content/themes
cd wp-content/themes
# Install Sage
composer create-project roots/sage your-theme-name dev-master
# Navigate to your-theme-name
cd your-theme-name
# Install all the necessary dependencies to run the build process
yarn
# OR
npm install
⚠️ HMR is not working … working on a fix ⚠️
dev@mailhog.local
as a result you’de see a warning, ignore it and check mailhog to see the emailetc/config/wordpress.ini
change xdebug.remote_host
to your local machine ip addressdocker restart appserver
if you changed the service name make sure to refrence it instead of appserverphp -i | grep Xdebug
you should see xdebug version ++ more information