Skip to content

Instantly share code, notes, and snippets.

@karlclement
Created August 15, 2017 22:42
Show Gist options
  • Select an option

  • Save karlclement/7ef3a5f39707f5317c3157b08bf720d5 to your computer and use it in GitHub Desktop.

Select an option

Save karlclement/7ef3a5f39707f5317c3157b08bf720d5 to your computer and use it in GitHub Desktop.
WP Vagrantfile
server {
listen 80;
server_name localhost your_domain_here.dev;
root /var/www/;
index index.php index.html;
# Important for VirtualBox
sendfile off;
# Add trailing slash
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* \.php {
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_cache off;
fastcgi_index index.php;
}
}
#!/bin/bash
DBUSER="<db user name here>"
DBPASS="<db pass here>"
DBNAME="<db name here>"
echo "Provisioning virtual machine..."
echo "Updating apt-get..."
sudo apt-get update > /dev/null
# Git
echo "Installing Git..."
sudo apt-get install -y git > /dev/null
# Vim
echo "Installing Vim..."
sudo apt-get install -y vim > /dev/null
# Nginx
echo "Installing Nginx..."
sudo apt-get install -y nginx > /dev/null
# PHP
echo "Updating PHP repository..."
sudo apt-get install -y python-software-properties build-essential > /dev/null
sudo add-apt-repository -y ppa:ondrej/php > /dev/null
echo "Updating apt-get once more..."
sudo apt-get update > /dev/null
echo "Installing PHP..."
sudo apt-get install -y php7.0 php7.0-fpm > /dev/null
echo "Installing PHP extensions..."
sudo apt-get install -y curl php7.0-curl php7.0-mysql > /dev/null
# MySQL
echo "Preparing MySQL..."
sudo apt-get install -y debconf-utils > /dev/null
debconf-set-selections <<< "mysql-server mysql-server/root_password password $DBPASS"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $DBPASS"
echo "Installing MySQL..."
sudo apt-get install -y mysql-server > /dev/null
mysql --user=root --password=$DBPASS -e "CREATE DATABASE $DBNAME;"
mysql --user=root --password=$DBPASS -e "GRANT ALL PRIVILEGES ON $DBNAME.* TO $DBUSER@localhost;"
mysql --user=root --password=$DBPASS -e "FLUSH PRIVILEGES;"
# Composer
echo "Installing Composer..."
sudo apt-get install -y php5-cli > /dev/null
curl -Ss https://getcomposer.org/installer | php > /dev/null
sudo mv composer.phar /usr/bin/composer
# Nginx Config
echo "Configuring Nginx..."
cp /var/www/.provision/config/nginx_vhost /etc/nginx/sites-available/nginx_vhost > /dev/null
ln -s /etc/nginx/sites-available/nginx_vhost /etc/nginx/sites-enabled/
rm -rf /etc/nginx/sites-available/default
# Restarting Nginx for config to take effect
echo "Restarting Nginx..."
service nginx restart > /dev/null
echo "Good to go! Visit your URL if you updated your hosts file"
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 80, host: 80, auto_correct: true
config.vm.network "forwarded_port", guest: 3306, host: 3309
# Private IP --> Add `192.168.68.9 your_domain_here.dev` to /etc/hosts file
config.vm.network :private_network, ip: "192.168.68.9"
config.vm.synced_folder "./", "/vagrant", disabled: true
config.vm.synced_folder "./", "/var/www", create: true, group: "www-data", owner: "www-data"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
config.vm.provision "shell" do |s|
s.path = ".provision/setup.sh"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment