Created
September 2, 2016 12:29
-
-
Save asmt3/c11c05f83bc1deee77bf9002b56b74f5 to your computer and use it in GitHub Desktop.
A Vagrant provisioning script to create an environment for Nginx/Node/Express/MySQL
This file contains hidden or 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
# VAGRANTFILE_API_VERSION = "2" | |
# VAGRANT_DOMAIN_NAME = "dev.xmas.justgiving.com" | |
# VAGRANT_IP_ADDRESS = "192.168.33.62" | |
# Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
# config.vm.box = "hashicorp/precise64" | |
# config.hostmanager.enabled = true | |
# config.hostmanager.manage_host = true | |
# config.hostmanager.manage_guest = true | |
# config.hostmanager.ignore_private_ip = false | |
# config.hostmanager.include_offline = true | |
# config.vm.network "private_network", ip: VAGRANT_IP_ADDRESS | |
# config.vm.hostname = VAGRANT_DOMAIN_NAME | |
# config.vm.provider :virtualbox do |vb| | |
# vb.customize ["modifyvm", :id, "--memory", "512"] | |
# end | |
# config.vm.synced_folder ".", "/vagrant" | |
# config.vm.provision :shell, :path => "system/provision.sh" | |
# end | |
#!/usr/bin/env bash | |
# Update | |
apt-get update | |
# Set timezone and install NTP | |
echo "Europe/London" > /etc/timezone | |
dpkg-reconfigure -f noninteractive tzdata | |
apt-get install -y ntp | |
# Install build tools | |
apt-get install -y build-essential git | |
# Add the repositories to install the latest version of nginx | |
apt-get install -y python-software-properties | |
add-apt-repository -y ppa:nginx/stable | |
apt-get update | |
# Download and install pre-compiled NodeJS v4.5 | |
cd /tmp && wget https://nodejs.org/dist/v4.5.0/node-v4.5.0-linux-x64.tar.xz && tar -xJvf node-v4.5.0-linux-x64.tar.xz && sudo cp node-v4.5.0-linux-x64/bin/node /usr/bin/node | |
# Download and install npm | |
cd /tmp | |
git clone git://github.com/isaacs/npm.git | |
cd npm/scripts | |
chmod +x install.sh | |
sudo ./install.sh | |
# Install Nodemon | |
sudo npm install -g nodemon | |
# Create logs directory | |
su - vagrant -c "mkdir /vagrant/system/logs" | |
# Install Nginx | |
apt-get install -y nginx | |
# Create backup copy of existing config files (nginx.conf and mime.types) | |
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak | |
cp /etc/nginx/mime.types /etc/nginx/mime.types.bak | |
# Create symlink to Nginx H5BP configuration files | |
mkdir /etc/nginx/conf | |
ln -sf /vagrant/system/nginx/nginx.conf /etc/nginx/nginx.conf | |
ln -sf /vagrant/system/nginx/mime.types /etc/nginx/mime.types | |
ln -s /vagrant/system/nginx/h5bp.conf /etc/nginx/conf/h5bp.conf | |
ln -s /vagrant/system/nginx/x-ua-compatible.conf /etc/nginx/conf/x-ua-compatible.conf | |
ln -s /vagrant/system/nginx/expires.conf /etc/nginx/conf/expires.conf | |
ln -s /vagrant/system/nginx/cross-domain-fonts.conf /etc/nginx/conf/cross-domain-fonts.conf | |
ln -s /vagrant/system/nginx/protect-system-files.conf /etc/nginx/conf/protect-system-files.conf | |
### Installing MySQL 5.5 | |
sudo debconf-set-selections <<< 'mysql-server-5.5 mysql-server/root_password password rootpass' | |
sudo debconf-set-selections <<< 'mysql-server-5.5 mysql-server/root_password_again password rootpass' | |
sudo apt-get update | |
sudo apt-get -y install mysql-server-5.5 | |
# create database only once | |
mysql -uroot -prootpass -e "create schema if not exists app" | |
# load schema | |
# /vagrant_data/application/backend/app/Console/cake schema create -y | |
# add test data | |
# mysql -uroot -prootpass --database app < /srv/Vagrant-config/sql/empty.sql | |
# Symlink to the proper log directory | |
ln -s /var/log/nginx /usr/share/nginx/logs | |
# Configure default site using server.conf | |
mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak | |
ln -s /vagrant/system/nginx/server.conf /etc/nginx/sites-available/default | |
# Create upstart job for Node.js app and Nginx | |
cp /vagrant/system/upstart/app.conf /etc/init/app.conf | |
cp /vagrant/system/upstart/nginx.conf /etc/init/nginx.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment