Skip to content

Instantly share code, notes, and snippets.

@bruceh48
Last active May 7, 2016 03:58
Show Gist options
  • Save bruceh48/a20f537565f18cc1b236960f5bab8938 to your computer and use it in GitHub Desktop.
Save bruceh48/a20f537565f18cc1b236960f5bab8938 to your computer and use it in GitHub Desktop.
Vagrant - Setup a Ubuntu/nginx/PHP5 box
# ssh into VagrantBox
sudo apt-get clean
# this next line can take quite some time to run..
sudo dd if=/dev/zero of=/EMPTY bs=1M
sudo rm -f /EMPTY
cat /dev/null > ~/.bash_history && history -c && exit
#exit out of Vagrantbox
vagrant package --output mynew.box
copy to /boxes
boxes bruce$ openssl sha1 newbox.box
# results in a line that looks like :
# SHA1(ubuntu14-nginx-php5.box)= 14f693b4f7efdd077fc8fe69554d07b54b906800
# Create a JSON file called mynew.json
{
"name": "mynew",
"description": "This box contains .....",
"versions": [{
"version": "0.1.0",
"providers": [{
"name": "virtualbox",
"url": "file:///Users/bruce/vagrant/boxes/mynew.box",
"checksum_type": "sha1",
"checksum": "14f693b4f7efdd077fc8fe69554d07b54b906800"
}]
}]
}
# save
# in Vagrant file use :
vb.vm.box = "mynew"
vb.vm.box_url = "file:///Users/bruce/vagrant/boxes/mynew.json"
#!/bin/sh -e
sudo apt-get update
sudo apt-get -y upgrade
# -- Available PHP modules, choose what you need --
# sudo apt-get install -y nginx php5-mysql php5-curl php5-gd php5-intl php-pear
# sudo apt-get install -y php5-imagick php5-imap php5-mcrypt php5-memcached
# sudo apt-get install -y php5-ming php5-ps php5-pspell php5-recode php5-snmp
# sudo apt-get install -y php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-xcache
sudo apt-get install -y nginx php5 php5-fpm php5-pgsql php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
# Set default PHP timezome to Australia/Perth
sudo sed -i "s/^;date.timezone =$/date.timezone = \"Australia\/Perth\"/" /etc/php5/fpm/php.ini
# Turn on Errors, so that we can see what is happening
sudo sed -i "s/^ç = Off$/display_errors = On/" /etc/php5/fpm/php.ini
sudo sed -i "s/^display_startup_errors = Off$/display_startup_errors = On/" /etc/php5/fpm/php.ini
sudo sed -i "s/^error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT$/error_reporting=E_ALL/" /etc/php5/fpm/php.ini
sudo sed -i "s/^;cgi.fix_pathinfo=1$/cgi.fix_pathinfo=0/" /etc/php5/fpm/php.ini
# Restart PHP
sudo service php5-fpm restart
# Lets male the website locations and copy over files
sudo mkdir -p /srv/pfsserver/www/
sudo cp /vagrant/website/index.php /srv/pfsserver/www/index.php
sudo rm -rf /etc/nginx/sites-available/default
sudo rm -rf /etc/nginx/sites-enabled/default
sudo cp /vagrant/sites-available/site.conf /etc/nginx/sites-available/site.conf
sudo ln -s /etc/nginx/sites-available/site.conf /etc/nginx/sites-enabled/site.conf
sudo nginx -t
sudo service nginx reload
server {
listen 80;
root /srv/pfsserver/www;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on /tmp/php5-fpm.sock
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
# -*- mode: ruby -*-
# vi: set ft=ruby :
setup = {
"name": "pfsserver",
"ip_address": "10.0.0.10",
"memory": 512
}
Vagrant.configure("2") do |config|
config.vm.define setup[:name] do |vb|
vb.vm.network :private_network, ip: setup[:ip_address]
# guest is the Vagrant machine, Host is my laptop
vb.vm.network "forwarded_port", guest: 22, host: 2210, id: "ssh"
#
# If first time, then run this..
# vagrant box add 'ubuntu64-perth' file://~/vagrant/boxes/ubuntu64-perth.box
vb.vm.box = "ubuntu64-perth"
vb.vm.box_url = "file:///Users/bruce/vagrant/boxes/ubuntu64-perth.json"
vb.vm.hostname = setup[:name]
vb.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
vb.ssh.username="vagrant"
vb.ssh.password ="vagrant"
vb.ssh.forward_agent = true
vb.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", setup[:memory],"--nictype1", "virtio"]
end
vb.vm.synced_folder ".", "/vagrant"
vb.vm.provision "shell", path: "setup.sh",run: "once"
vb.vm.provision "shell", inline:"echo "+setup[:name]+" on "+setup[:ip_address], run: "always"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment