Last active
January 11, 2016 05:19
-
-
Save sumpygump/9499540 to your computer and use it in GitHub Desktop.
Simple Vagrantfile
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 : | |
# Version: 1.1.0 | |
# Settings for this VM | |
VM_HOSTNAME = "php55.dev" | |
VM_IPADDRESS = "192.168.100.5" | |
MYSQL_ROOT_PW = "1111" | |
TIMEZONE = "America/Chicago" | |
# This is the webroot on the VM and will map to the current directory's 'web' | |
# directory. | |
WEB_ROOT = "/srv/web" | |
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | |
VAGRANTFILE_API_VERSION = "2" | |
$script = <<-EOF | |
#!/usr/bin/env bash | |
hr() { echo "--------------------------------"; } | |
echocontext() { echo "[provision] $1"; } | |
taskdone() { echocontext "done."; } | |
echoerr() { echocontext "$1" 1>&2; } | |
# Install packages via apt-get | |
hr; echocontext "Installing packages via apt-get..." | |
apt-get update | |
debconf-set-selections <<< 'mysql-server mysql-server/root_password password #{MYSQL_ROOT_PW}' | |
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password #{MYSQL_ROOT_PW}' | |
apt-get install -y language-pack-en apache2 mysql-server mysql-client php5 php5-json php5-xdebug php5-dev php5-mysql php5-intl git tree imagemagick figlet htop | |
taskdone | |
# Setting servername to eliminate errors when restarting apache | |
hr; echocontext "Setting ServerName..." | |
cat /etc/apache2/apache2.conf | grep ServerName | |
if [ $? -eq 1 ]; then | |
echo 'ServerName 127.0.0.1' >> /etc/apache2/apache2.conf | |
fi | |
taskdone | |
# Set web root | |
hr; echocontext "Setting web root..." | |
if [ -e "/srv/web/index.html" ]; then | |
echoerr "Web root already set up" | |
else | |
mkdir -p /srv/web | |
cp /var/www/index.html /srv/web | |
rm -rf /var/www | |
ln -s /srv/web /var/www | |
fi | |
taskdone | |
# Update timezone setting in php.ini | |
hr; echocontext "Updating timezone in php.ini..." | |
sed -e 's#;date.timezone =#date.timezone = #{TIMEZONE}#' /etc/php5/cli/php.ini > /tmp/php.ini; cp /tmp/php.ini /etc/php5/cli/php.ini | |
sed -e 's#;date.timezone =#date.timezone = #{TIMEZONE}#' /etc/php5/apache2/php.ini > /tmp/php.ini; cp /tmp/php.ini /etc/php5/apache2/php.ini | |
taskdone | |
# Update ini settings for php xdebug | |
hr; echocontext "Updating xdebug settings..." | |
cat /etc/php5/mods-available/xdebug.ini | grep max_nesting_level | |
if [ $? -eq 1 ]; then | |
echo -e '; Set max nesting level to avoid infinite recursion protection\n; erroneously throwing fatal errors\nxdebug.max_nesting_level=250' >> /etc/php5/mods-available/xdebug.ini | |
fi | |
taskdone | |
# Update .bashrc | |
hr; echocontext "Updating .bashrc..." | |
sed -e 's/#force_color_prompt=yes/force_color_prompt=yes/' /home/vagrant/.bashrc > /tmp/.bashrc; cp /tmp/.bashrc /home/vagrant/.bashrc | |
taskdone | |
# Make bin dir in home | |
hr; echocontext "Installing bin directory in home..." | |
mkdir -p /home/vagrant/bin | |
taskdone | |
# Install composer | |
hr; echocontext "Installing composer..." | |
cd /home/vagrant/bin | |
if [ -e "composer" ]; then | |
echoerr "composer already exists; updating" | |
/home/vagrant/bin/composer self-update | |
else | |
curl -sS https://getcomposer.org/installer | php -- --install-dir=/home/vagrant/bin | |
mv -v /home/vagrant/bin/composer.phar /home/vagrant/bin/composer | |
fi | |
taskdone | |
# Install phing | |
hr; echocontext "Installing phing..." | |
if [ -e "/home/vagrant/.composer/vendor/bin/phing" ]; then | |
echoerr "phing already exists; skipping" | |
else | |
COMPOSER_HOME=/home/vagrant/.composer /home/vagrant/bin/composer global require "phing/phing=>=2.5" | |
echo 'export PATH=~/.composer/vendor/bin:$PATH' >> /home/vagrant/.bashrc | |
chown vagrant.vagrant /home/vagrant/.composer -R | |
fi | |
taskdone | |
# Fix permissions | |
hr; echocontext "Fixing permissions..." | |
chown vagrant /home/vagrant -R | |
chgrp vagrant /home/vagrant -R | |
chmod a+r /var/log/apache2 -R | |
chmod a+x /var/log/apache2 | |
taskdone | |
# Update AllowOverride directive in Apache | |
hr; echocontext "Enabling apache AllowOverride..." | |
cat /etc/apache2/sites-available/000-default.conf | grep AllowOverride | |
if [ $? -eq 1 ]; then | |
sed -e 's#DocumentRoot /var/www#DocumentRoot /var/www\\n <Directory /var/www/>\\n AllowOverride All\\n </Directory>#' /etc/apache2/sites-available/000-default.conf > /tmp/000-default.conf; cp /tmp/000-default.conf /etc/apache2/sites-available/000-default.conf | |
fi | |
taskdone | |
# Enable apache mod_rewrite | |
hr; echocontext "Enabling apache mod_rewrite..." | |
a2enmod rewrite | |
service apache2 restart | |
taskdone | |
hr; figlet "Done" | |
echo "IP ADDRESS: #{VM_IPADDRESS}" | |
echo "Shared folder at /srv" | |
echo "Web root (on VM): #{WEB_ROOT}" | |
EOF | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
# Box | |
config.vm.box = "ubuntu/trusty64" | |
config.vm.hostname = VM_HOSTNAME | |
# Shared folders | |
config.vm.synced_folder '.', '/srv', :nfs => true | |
# Provision | |
config.vm.provision :shell, :inline => $script | |
# Network | |
config.vm.network "private_network", ip: VM_IPADDRESS | |
# VirtualBox | |
config.vm.provider :virtualbox do |vb| | |
vb.customize ['modifyvm', :id, '--name', VM_HOSTNAME] | |
end | |
end |
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 : | |
# Version: 1.1.1 | |
# Settings for this VM | |
VM_HOSTNAME = "sumpygump.vm2.dev" | |
VM_IPADDRESS = "192.168.100.2" | |
MYSQL_ROOT_PW = "1111" | |
TIMEZONE = "America/Chicago" | |
# This is the webroot on the VM and will map to the current directory's 'web' | |
# directory. | |
WEB_ROOT = "/srv/web" | |
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | |
VAGRANTFILE_API_VERSION = "2" | |
$script = <<-EOF | |
#!/usr/bin/env bash | |
hr() { echo "--------------------------------"; } | |
echocontext() { echo "[provision] $1"; } | |
taskdone() { echocontext "done."; } | |
echoerr() { echocontext "$1" 1>&2; } | |
# Install packages via apt-get | |
hr; echocontext "Installing packages via apt-get..." | |
apt-get update | |
debconf-set-selections <<< 'mysql-server mysql-server/root_password password #{MYSQL_ROOT_PW}' | |
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password #{MYSQL_ROOT_PW}' | |
apt-get install -y language-pack-en apache2 mysql-server mysql-client php5 php5-json php5-xdebug php5-dev php5-mysql exuberant-ctags git tree jp2a imagemagick figlet htop ack-grep | |
taskdone | |
# Setting servername to eliminate errors when restarting apache | |
hr; echocontext "Setting ServerName..." | |
cat /etc/apache2/apache2.conf | grep ServerName | |
if [ $? -eq 1 ]; then | |
echo 'ServerName 127.0.0.1' >> /etc/apache2/apache2.conf | |
fi | |
taskdone | |
# Set web root | |
hr; echocontext "Setting web root..." | |
if [ -e "/srv/web/index.html" ]; then | |
echoerr "Web root already set up" | |
else | |
mkdir -p /srv/web | |
cp /var/www/index.html /srv/web | |
rm -rf /var/www | |
ln -s /srv/web /var/www | |
fi | |
taskdone | |
# Update timezone setting in php.ini | |
hr; echocontext "Updating timezone in php.ini..." | |
sed -e 's#;date.timezone =#date.timezone = #{TIMEZONE}#' /etc/php5/cli/php.ini > /tmp/php.ini; cp /tmp/php.ini /etc/php5/cli/php.ini | |
sed -e 's#;date.timezone =#date.timezone = #{TIMEZONE}#' /etc/php5/apache2/php.ini > /tmp/php.ini; cp /tmp/php.ini /etc/php5/apache2/php.ini | |
taskdone | |
# Update ini settings for php xdebug | |
hr; echocontext "Updating xdebug settings..." | |
cat /etc/php5/mods-available/xdebug.ini | grep max_nesting_level | |
if [ $? -eq 1 ]; then | |
echo -e '; Set max nesting level to avoid infinite recursion protection\n; erroneously throwing fatal errors\nxdebug.max_nesting_level=250' >> /etc/php5/mods-available/xdebug.ini | |
fi | |
taskdone | |
# Update .bashrc | |
hr; echocontext "Updating .bashrc..." | |
sed -e 's/#force_color_prompt=yes/force_color_prompt=yes/' /home/vagrant/.bashrc > /tmp/.bashrc; cp /tmp/.bashrc /home/vagrant/.bashrc | |
taskdone | |
# Make bin dir in home | |
hr; echocontext "Installing bin directory in home..." | |
mkdir -p /home/vagrant/bin | |
taskdone | |
# Install composer | |
hr; echocontext "Installing composer..." | |
cd /home/vagrant/bin | |
if [ -e "composer" ]; then | |
echoerr "composer already exists; updating" | |
/home/vagrant/bin/composer self-update | |
else | |
curl -sS https://getcomposer.org/installer | php -- --install-dir=/home/vagrant/bin | |
mv -v /home/vagrant/bin/composer.phar /home/vagrant/bin/composer | |
fi | |
taskdone | |
# Install phing | |
hr; echocontext "Installing phing..." | |
if [ -e "/home/vagrant/.composer/vendor/bin/phing" ]; then | |
echoerr "phing already exists; skipping" | |
else | |
COMPOSER_HOME=/home/vagrant/.composer /home/vagrant/bin/composer global require "phing/phing=>=2.5" | |
echo 'export PATH=~/.composer/vendor/bin:$PATH' >> /home/vagrant/.bashrc | |
chown vagrant.vagrant /home/vagrant/.composer -R | |
fi | |
taskdone | |
# Fix permissions | |
hr; echocontext "Fixing permissions..." | |
chown vagrant /home/vagrant -R | |
chgrp vagrant /home/vagrant -R | |
chmod a+r /var/log/apache2 -R | |
chmod a+x /var/log/apache2 | |
taskdone | |
# Update AllowOverride directive in Apache | |
hr; echocontext "Enabling apache AllowOverride..." | |
cat /etc/apache2/sites-available/000-default.conf | grep AllowOverride | |
if [ $? -eq 1 ]; then | |
sed -e 's#DocumentRoot /var/www/html#DocumentRoot /var/www\\n <Directory /var/www/>\\n AllowOverride All\\n </Directory>#' /etc/apache2/sites-available/000-default.conf > /tmp/000-default.conf; cp /tmp/000-default.conf /etc/apache2/sites-available/000-default.conf | |
fi | |
taskdone | |
# Enable apache mod_rewrite | |
hr; echocontext "Enabling apache mod_rewrite..." | |
a2enmod rewrite | |
service apache2 restart | |
taskdone | |
# Add .bash_aliases | |
hr; echocontext "Installing .bash_aliases..." | |
cd /home/vagrant/ | |
if [ -e ".bash_aliases" ]; then | |
echoerr ".bash_aliases already installed; skipping." | |
else | |
wget -q https://raw.githubusercontent.com/sumpygump/dotfiles/master/bash/.bash_aliases | |
chown vagrant .bash_aliases | |
chgrp vagrant .bash_aliases | |
fi | |
taskdone | |
# Install vim bundles | |
hr; echocontext "Installing vimrc bundles..." | |
if [ -d "/home/vagrant/vimrc" ]; then | |
echoerr "vimrc already exists; skipping." | |
else | |
cd /home/vagrant | |
git clone git://github.com/sumpygump/vimrc.git | |
cd vimrc | |
git submodule init | |
git submodule update | |
cd .. | |
ln -s vimrc/vim .vim | |
ln -s .vim/vimrc .vimrc | |
chown vagrant .vim/tmp | |
chgrp vagrant .vim/tmp | |
fi | |
taskdone | |
# Install git-info | |
hr; echocontext "Installing git-info..." | |
cd /home/vagrant/bin | |
if [ -e "git-info" ]; then | |
echoerr "git-info already exists; skipping." | |
else | |
wget -q https://raw.githubusercontent.com/sumpygump/dotfiles/master/bin/git-info | |
chmod a+x git-info | |
fi | |
taskdone | |
# Install .gitconfig | |
hr; echocontext "Installing .gitconfig..." | |
cd /home/vagrant/bin | |
if [ -e ".gitconfig" ]; then | |
echoerr ".gitconfig already exists; skipping." | |
else | |
wget -q https://raw.githubusercontent.com/sumpygump/dotfiles/master/git/.gitconfig | |
fi | |
taskdone | |
# Install .gitprompt | |
hr; echocontext "Installing .gitprompt..." | |
cd /home/vagrant/bin | |
if [ -e ".gitprompt" ]; then | |
echoerr ".gitprompt already exists; skipping." | |
else | |
wget -q https://raw.githubusercontent.com/sumpygump/dotfiles/master/git/.gitprompt | |
fi | |
echo "To use, run 'source ~/.gitprompt'" | |
taskdone | |
# Install ascimg | |
hr; echocontext "Installing ascimg..." | |
cd /home/vagrant/bin | |
if [ -e "ascimg" ]; then | |
echoerr "ascimg already exists; skipping." | |
else | |
wget -q https://raw.githubusercontent.com/sumpygump/dotfiles/master/bin/ascimg | |
chmod a+x ascimg | |
fi | |
taskdone | |
# Fix permissions | |
hr; echocontext "Fixing permissions..." | |
chown vagrant /home/vagrant -R | |
chgrp vagrant /home/vagrant -R | |
taskdone | |
hr; figlet "Done" | |
echo "IP ADDRESS: #{VM_IPADDRESS}" | |
echo "Shared folder at /srv" | |
echo "Web root (on VM): #{WEB_ROOT}" | |
EOF | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
# Box | |
config.vm.box = "ubuntu/trusty64" | |
config.vm.hostname = VM_HOSTNAME | |
# Shared folders | |
config.vm.synced_folder '.', '/srv', :nfs => true | |
# Provision | |
config.vm.provision :shell, :inline => $script | |
# Network | |
config.vm.network "private_network", ip: VM_IPADDRESS | |
# VirtualBox | |
config.vm.provider :virtualbox do |vb| | |
vb.customize ['modifyvm', :id, '--name', VM_HOSTNAME] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment