Created
November 30, 2015 15:01
-
-
Save martinkr/8a52fe4232cd8458a05e to your computer and use it in GitHub Desktop.
Vagrant: a simple setup with ngnix and php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "./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; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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