Skip to content

digitalquery/wp-vagrant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vagrant Box with Ubuntu 18.04, Nginx, MySQL and PHP-FPM

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:

Summary

  • 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

Acknowledgements

This Vagrant box and provisioning is based on this box from Paul Herron and the accompanying blog post.

What's included in the VM?

  • 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

Instructions

These instructions are OS X specific, but the overall solution should work on any platform that Vagrant and VirtualBox support.

Before you start

Fresh WP install

Use these instructions if you want to create a new WP site with the default empty database.

  1. Create directory for the site:
    • mkdir testsite
  2. cd to this created directory
  3. Clone the wp-vagrant folder here
    • git clone https://github.com/digitalquery/wp-vagrant.git
  4. Copy the VagrantFile into the site root directory
    • cp wp-vagrant/Vagrantfile .
  5. 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
  6. Browse to your hostname - you should see the default twentyfourteen theme

Existing WP install

Use these intructions if you have an existing WP install

  1. Go to the folder
  2. Clone the wp-vagrant repo
    • git clone git@github.com:digitalquery/wp-vagrant.git
    • This creates a subfolder called wp-vagrant
  3. Copy the Vagrantfile into the site root directory
    • cp wp-vagrant/Vagrantfile .
    • Or alternatively, create a symbolic link:
    • ln -s wp-vagrant/Vagrantfile Vagrantfile
  4. 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
  5. 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 and wp_db_password
      • If the wp-config file uses something different than root and the mysql_root_password then change these
      • Otherwise leave blank
    • 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
  6. vagrant up
  7. Browse to your hostname - and you should see your site up and running

PHP version

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

Settings.sh

The full list - more comments and explanation are in the settings.shfile itself.

Basic Settings
  • 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 database credentials
  • wp_db_name='vagrant_test'
  • wp_db_user=''
  • wp_db_password=''
WP admin and site setup details
  • wp_admin_user='admin'
  • wp_admin_password='123'
  • wp_admin_email='root@wpvagrant.test'
  • wp_site_title='Vagrant'
Database import
  • import_database=false
  • import_site_domain=''