A Vagrant setup to create an Ubuntu 18.04 (Bionic) virtual machine with Nginx, MySQL and PHP for WordPress development.
Intended to be as simple as possible:
- Quickly create a fresh WP instance served up via the Vagrant server.
- Optionally specify which version of WP to install
- Choose PHP 5.6, 7.0, 7.1, 7.2, or 7.3
- Can be dropped into an existing WP directory to provide a LEMP testing and development server with minimal config changes
- Can load database dump as part of provisioning
- Renames all domain references using WP-CLI
- Dumps the database to the shared folder on
vagrant destroy
— (this needs the vagrant triggers plugin to be installed from (https://github.com/emyl/vagrant-triggers)) - Remote debugging using XDebug
This Vagrant box and provisioning is based on this box from Paul Herron and the accompanying blog post.
- Ubuntu 18.04 LTS (Bionic Beaver) (https://app.vagrantup.com/ubuntu/boxes/bionic64)
- Nginx, listening on port 80
- MySQL, listening for remote connections
- Choose between PHP 5.6, 7.0, 7.1, 7.2, or 7.3, with OpCache and XDebug
- PHP-FPM
- Byobu
- WP-CLI
- APCu
- Dump database automatically on
vagrant destroy
These instructions are OS X specific, but the overall solution should work on any platform that Vagrant and VirtualBox support.
-
Install Homebrew (http://brew.sh/)
-
If you want to install VirtualBox and Vagrant with Homebrew then install brew-cask:
brew tap caskroom/cask
brew install brew-cask
-
Install VirtualBox
- Either download from the VirtualBox site (https://www.virtualbox.org/wiki/Downloads)
- Or, install via homebrew
brew cask install virtualbox
-
Install Vagrant
- Either download from the Vagrant site (https://www.vagrantup.com/downloads.html)
- Or, install via homebrew
brew cask install vagrant
-
Install vagrant-hostmanager
vagrant plugin install vagrant-hostmanager
-
Install Vagrant triggers
vagrant plugin install vagrant-triggers
-
Install vagrant-hostupdater
vagrant plugin install vagrant-hostsupdater
Use these instructions if you want to create a new WP site with the default empty database.
- Create directory for the site:
mkdir testsite
cd
to this created directory- Clone the wp-vagrant folder here
git clone https://github.com/digitalquery/wp-vagrant.git
- Copy the VagrantFile into the site root directory
cp wp-vagrant/Vagrantfile .
- Fire up Vagrant to create the VM and then run the provisioning scripts
vagrant up
- This may take a little while as the provisioning scripts download and install everything
- Browse to your hostname - you should see the default twentyfourteen theme
Use these intructions if you have an existing WP install
- Go to the folder
- Clone the wp-vagrant repo
git clone git@github.com:digitalquery/wp-vagrant.git
- This creates a subfolder called
wp-vagrant
- Copy the
Vagrantfile
into the site root directorycp wp-vagrant/Vagrantfile .
- Or alternatively, create a symbolic link:
ln -s wp-vagrant/Vagrantfile Vagrantfile
- If you want to import a database during the provisioning, then put a SQL dump file into the
wp-vagrant
folder. This file must have a .sql extension - Using your editor of choice, edit
wp-vagrant/settings.sh
install_wordpress=false
- the default for this is true, so change to false
wp_db_name=<db_name>
- should be the same database name as in wp-config.php
wp_db_user
andwp_db_password
- If the wp-config file uses something different than root and the
mysql_root_password
then change these - Otherwise leave blank
- If the wp-config file uses something different than root and the
- Leave the WP admin section variables empty
import_database=true
- set to true if you want to import a database ( and have a SQL dump file in the wp-vagrant folder)
import_site_domain=''
- Put the domain that you were using, this should be the same domain as the database dump.
- We will search for this domain in the database and change it to $hostname
vagrant up
- Browse to your hostname - and you should see your site up and running
To change the PHP version, edit settings.sh
and set the php_version
setting to 5.6, 7.0, 7.1, 7.2, or 7.3. Run vagrant provision
if you're changing an already created vagrant instance
The full list - more comments and explanation are in the settings.sh
file itself.
hostname='wpvagrant.test' # change this in the Vagrantfile as well
php_version='7.2' # valid values: '5.6', '7.0', '7.1', '7.2', or '7.3'
install_wordpress=true # change to false if this is being dropped in to an existing WP folder
wp_version="" # eg wp_version="3.5.2 or 4.0-beta1". Leave blank for latest stable release
wp_path='/vagrant'
mysql_root_password='root'
wp_db_name='vagrant_test'
wp_db_user=''
wp_db_password=''
wp_admin_user='admin'
wp_admin_password='123'
wp_admin_email='root@wpvagrant.test'
wp_site_title='Vagrant'
import_database=false
import_site_domain=''