/vagrant-docker-wordpress

Using Vagrant and Docker, setup a local development environment for WordPress.

Primary LanguageShell

WordPress Local Development Environment

Requirements

Create development environment

Copy Vagrant sample variables file and update it as needed.

# create variable file from sample
cp vagrant.yaml.sample vagrant.yaml
# edit file
vim vagrant.yaml

Clone WordPress site into the wordpress directory.

git clone https://.... wordpress

Move/copy database dump into sql directory.

mv /path/to/sql/file.sql sql/dump.sql

Create the Vagrant VM (and provision it).

vagrant up

Update local hosts (/etc/hosts) file.

sudo hostctl add domains PROFILE_NAME LOCAL_DOMAIN_NAME_FROM_VAGRANT_YAML --ip "IP_FROM_VAGRANT_YAML"

Login into Vagrant VM and start services

# ssh into vagrant vm
vagrant ssh
# Run all services
docker compose -f /home/vagrant/dockerfiles/docker-compose.yml up

Access the local site from the browser or check it with curl.

curl -v LOCAL_DOMAIN_NAME_FROM_VAGRANT_YAML

Run commands in the running services or stop/remove them.

# Exec a command inside a running service
docker compose -f /home/vagrant/dockerfiles/docker-compose.yml exec wordpress /bin/bash
# Remove running/stopped services
docker compose -f /home/vagrant/dockerfiles/docker-compose.yml rm --stop --force