!! Contributions are welcome
- Docker: https://docs.docker.com/get-docker/
- SourceTree: https://www.sourcetreeapp.com/
- SSH Setup to connect to WPEngine: https://wpengine.com/support/ssh-gateway/
- Containerized Docker build.
- Separate docker services for Wordpress (wordpress), MySQL database (db), phpMyAdmin (pma), NGINX (nginx). Additionally, a container for mysql-tunnel to connect to external database.
- Ability to run this code with either local database, or directly connected to external database on your wpengine instance.
- Automated deployment to Development, Staging and Production.
Download this repository and upload on your BitBucket account. Create 3 branches:
1. release/development
2. release/staging
3. release/production
You can name these branches however you like, the caveat is that bitbucket-pipelines.yml must be modified correspondingly for automated deployments. Finally, clone in SourceTree.
Put your wordpress website in wordpress folder. Make sure you do not delete any existing files.
You will need to edit a bunch of files to update your wpengine environment names. Namely these three variables: WPEENVNAMEDEV, WPEENVNAMESTAG, WPEENVNAMEPROD, for development, staging, and production wpengine environment names respectively. Files that must be edited:
- bitbucket-pipelines.yml
- scripts in migration folder
- get_uploads.sh
- send_uploads.sh
- pull_db.sh
For NGINX, you will need to generate local certificates and trust them.
Use the create-cert.sh and trust-cert.sh scripts in certificate_scripts folder.
Run ./get_uploads.sh to sync wp-content/uploads folder from your wpengine dev server to your local repository. (Don't forget to chmod +x get_uploads.sh the first time only).
Note: Run this script everytime you take a new pull from remote repository.
There are two main run options:
-
Run with database container and database deployed locally (also includes phpMyAdmin container), we will call it
with-local-dbfor the remainder of this document. -
Run with only wordpress container, connected to external development database. Let's call this one
with-external-db. Note that if you use this option, you will be directly modifying the external db on your wpengine environment. Use with caution.
Fire up the Terminal. Move to repository folder.
cd /path/to/repository- Rename
docker-compose-local.ymlfile todocker-compose.yml. - Rename
wp-config-local.phpfile towp-config.phpin wordpress folder.
cp docker-compose-local.yml docker-compose.yml
cd wordpress # Go inside wordpress folder
cp wp-config-local.php wp-config.php
cd .. # Go back to repository rootProtip: You can copy paste this entire block in terminal and it will run each command. Just press enter afterwards.
- Rename
docker-compose-external.ymlfile todocker-compose.yml. - Rename
wp-config-external.phpfile towp-config.phpin wordpress folder.
cp docker-compose-external.yml docker-compose.yml
cd wordpress # Go inside wordpress folder
cp wp-config-external.php wp-config.php
cd .. # Go back to repository rootProtip: You can copy paste this entire block in terminal and it will run each command. Just press enter afterwards.
Note: All commands must be executed when you have run cd to repository directory.
----> Skip this step if you're using the with-external-db option. Pull latest database
./pull_db.shTo make things easier for next time, set an alias:
alias pulldb=./pull_db.shSo instead of writing ./pull_db.sh, simply execute pulldb command.
If the script doesn't execute: chmod +x pull_db.sh to tell your OS it's an executable file.
Build the images and run the containers.
docker-compose up --buildor if you want to run it in detached (background) mode:
docker-compose up -d --buildMake sure all containers are running:
docker-compose pswordpress
pma
dbWordpress available at: http://localhost.
phpMyAdmin available at: http://localhost:8080.
For external option, there should be no db or pma container so you will only see wordpress running.
Running on different ports
You can change the default ports in docker-compose.yml file. For example, 8080:80 describes local_port:container_port. You only need to change the first port to change your localhost port.
Want to reset everything?
docker-compose down -v
docker-compose up --build
Finally, test that everything works by going to http://localhost/wp-admin and entering your username/password that you have on wpengine development environment.
- Merge/Commit code to
release/developmentbranch to trigger automated deployment of code. - Run
./send_uploads.shto sync local uploads folder to wpengine development environment. - Test if everything is working correctly.
- Check the scripts under
database-versioning. - Manually run whichever scripts need to be run through phpMyAdmin on development environment.
- Merge code of
release/developmentbranch torelease/stagingto trigger automated deployment of code.- You can do this by going to
release/developmentbranch. - Click on
Merge - Select source as
release/development. - Select destination as
release/staging.
- You can do this by going to
- Manually upload what needs to be uploaded to
wp-content/uploadsfolder from development to staging through sftp. - Test if everything is working correctly.
- Merge code of
release/stagingbranch torelease/productionto trigger automated deployment of code.- You can do this by going to
release/stagingbranch. - Click on
Merge - Select source as
release/staging. - Select destination as
release/production.
- You can do this by going to
- Manually upload what needs to be uploaded to
wp-content/uploadsfolder from staging to production through sftp. - Test if everything is working correctly.