Skip to content

Instantly share code, notes, and snippets.

@blackbirdcoder
Forked from martinkr/Vagrantfile
Created February 24, 2024 14:04
Show Gist options
  • Save blackbirdcoder/a0b1367f9d04c6d77f1e71941306bdf4 to your computer and use it in GitHub Desktop.
Save blackbirdcoder/a0b1367f9d04c6d77f1e71941306bdf4 to your computer and use it in GitHub Desktop.
Vagrant: a simple setup with ngnix and php
#!/usr/bin/env bash
# "./tools/vagrant/bootstrap.sh"
echo "Provisioning virtual machine..."
echo "Updating packages list"
apt-get update
# Nginx
echo "Installing Nginx"
apt-get install nginx -y
# Nginx Configuration
echo "Configuring Nginx"
sudo cp /vagrant/tools/vagrant/nginx_vhost /etc/nginx/sites-available/nginx_vhost
sudo ln -sf /etc/nginx/sites-available/nginx_vhost /etc/nginx/sites-enabled/
sudo rm -rf /etc/nginx/sites-available/default
# php
echo "Installing php"
sudo apt-get install php5-common php5-cli php5-fpm -y
# Restart Nginx for the config to take effect
echo "Restarting Nginx"
sudo service nginx restart
# "./tools/vagrant/ngnix_vhost"
# develop
server {
listen 8080;
listen [::]:8080 ipv6only=on;
server_name localhost;
root /var/www;
index index.html index.php;
# Important for VirtualBox
sendfile off;
# Gzip Settings
gzip on;
gzip_disable "msie6";
location / {
try_files $uri $uri/ =404;
autoindex on;
}
# enable php
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
# -*- mode: ruby -*-
# vi: set ft=ruby :
# "./Vagrantfile"
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
# set ports: according to your ngnix configuration
config.vm.network :forwarded_port, guest: 8080, host: 8080
# sync to the ngnix root
config.vm.synced_folder "./", "/var/www", create: true, group: "www-data", owner: "www-data"
# remove error message
config.vm.provision "fix-no-tty", type: "shell" do |s|
s.privileged = false
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
end
# use bootrap.sh
config.vm.provision "shell", path: "./tools/vagrant/bootstrap.sh"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment