Skip to content

Instantly share code, notes, and snippets.

@thomaswilburn
Last active October 22, 2015 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaswilburn/be6869e0d647442a1a7e to your computer and use it in GitHub Desktop.
Save thomaswilburn/be6869e0d647442a1a7e to your computer and use it in GitHub Desktop.
Very simple WordPress Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
# This sets the VM that we want to use - in this case, a classic Ubuntu 12.01 box
config.vm.box = "hashicorp/precise32"
# This makes the VM available in your browser on port 8080, and on MySQL's default port
config.vm.network "forwarded_port", guest: 80, host: 8080 #HTTP
config.vm.network "forwarded_port", guest: 3306, host: 3306 #MySQL
# Uncomment the next line if you want to give it a distinct IP address (may not work on Windows 10)
# config.vm.network "private_network", ip: "192.168.33.10"
# We want to share a folder with the VM - namely, the web root of the server
config.vm.synced_folder "./www", "/var/www", create: true, :mount_options => ["dmode=777", "fmode=666"]
# Next, we'll set up the VM by running some shell commands on first boot
config.vm.provision "shell", inline: <<-SHELL
#install software
debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
echo "Updating software listings..."
sudo apt-get update -qq
echo "Installing software from repositories..."
sudo apt-get -y -q -o=Dpkg::Use-Pty=0 install apache2 mysql-server php5 php5-mysql git curl
#create database
echo "Creating MySQL database..."
mysql -u root --password='root' --execute='CREATE DATABASE IF NOT EXISTS wordpress;'
#add the `vagrant` user to the www-group
sudo adduser vagrant www-data
#download and install WordPress
echo "Downloading and installing WordPress"
cd /var/www
curl -s https://wordpress.org/latest.tar.gz | tar xz --strip-components=1
mv index.html _index.html
#restart Apache (sometimes it doesn't see PHP's MySQL adapter)
sudo /etc/init.d/apache2 restart
SHELL
config.vm.post_up_message = <<-POSTUP
Your virtual machine is now up and running.
To pause this VM, use the `vagrant suspend` command.
To restart it after pausing, use `vagrant resume`.
To shut down completely, use `vagrant halt`.
And to start it after shutdown, use `vagrant up`.
Visit http://localhost:8080 to visit your local server. Web files are located in the www/ folder in this directory. They will not be erased when you halt or restart the server, and you can edit them using a normal desktop editor. You can also clone your theme into www/wp-content/themes to work on it.
MySQL config info for WordPress:
Database name: wordpress
User name: root
Password: root
Database host: localhost
Table Prefix: wp_
POSTUP
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment