Skip to content

Instantly share code, notes, and snippets.

@jrnickell
Last active December 21, 2015 10:09
Show Gist options
  • Save jrnickell/6289943 to your computer and use it in GitHub Desktop.
Save jrnickell/6289943 to your computer and use it in GitHub Desktop.
Shell provisioning for Vagrant
# !/bin/bash --login -x
# cd to home
cd ~
# exit if php is already installed
which php && { echo "Tools already installed."; exit 0; }
# repo for php5 - until php5.4 is added to Ubuntu 12.04
add-apt-repository -y ppa:ondrej/php5-oldstable
# update
apt-get update
# debconf utils
apt-get install -y debconf-utils
# parameters
echo "grub-pc grub-pc/kopt_extracted boolean true" | debconf-set-selections
echo "grub-pc grub2/linux_cmdline string" | debconf-set-selections
echo "grub-pc grub-pc/install_devices multiselect /dev/sda" | debconf-set-selections
echo "grub-pc grub-pc/install_devices_failed_upgrade boolean true" | debconf-set-selections
echo "grub-pc grub-pc/install_devices_disks_changed multiselect /dev/sda" | debconf-set-selections
echo "mysql-server mysql-server/root_password password admin" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password admin" | debconf-set-selections
echo "phpmyadmin phpmyadmin/dbconfig-install boolean true" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/admin-pass password admin" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/app-pass password admin" | debconf-set-selections
echo "phpmyadmin phpmyadmin/app-password-confirm password admin" | debconf-set-selections
echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2" | debconf-set-selections
# vagrant grub fix
dpkg-reconfigure -f noninteractive grub-pc
# upgrade
apt-get upgrade -y
# basic tools
apt-get install -y aptitude
apt-get install -y wget
apt-get install -y curl
apt-get install -y git
apt-get install -y vim
apt-get install -y cron
apt-get install -y python-software-properties
apt-get install -y python
apt-get install -y g++
apt-get install -y make
apt-get install -y build-essential
apt-get install -y openssl
apt-get install -y subversion
# apache2
apt-get install -y apache2
echo "ServerName localhost" | tee /etc/apache2/conf.d/fqdn
a2enmod rewrite
a2enmod headers
a2enmod filter
a2enmod expires
a2enmod include
# php
apt-get install -y php5
apt-get install -y libapache2-mod-php5
apt-get install -y php5-dev
# mysql
apt-get install -q -y mysql-server
apt-get install -y libapache2-mod-auth-mysql
apt-get install -y php5-mysql
# sqlite
apt-get install -y sqlite3
# phpmyadmin
apt-get install -q -y phpmyadmin
# imagemagick
apt-get install -y imagemagick
# php extensions
apt-get install -y php-apc
apt-get install -y php5-curl
apt-get install -y php5-intl
apt-get install -y php5-xdebug
apt-get install -y php5-xmlrpc
apt-get install -y php5-xsl
apt-get install -y php5-sqlite
apt-get install -y php5-imagick
# composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
# pear
apt-get install -y php-pear
# phpunit, apigen, phing, and phpQA tools
pear config-set auto_discover 1
pear install --alldeps pear.phpunit.de/PHPUnit
pear install --alldeps pear.apigen.org/apigen
pear install --alldeps pear.phpqatools.org/phpqatools
pear channel-discover pear.phing.info
pear config-set preferred_state alpha
pear install --alldeps phing/phing
pear config-set preferred_state stable
# apigen temporary fix
mkdir /usr/share/php/Texy
ln -s /usr/share/php/texy/src/texy.php /usr/share/php/Texy/texy.php
# restart apache
service apache2 restart
# ruby dependencies
apt-get install -y libreadline6
apt-get install -y libreadline6-dev
apt-get install -y zlib1g
apt-get install -y zlib1g-dev
apt-get install -y libssl-dev
apt-get install -y libyaml-dev
apt-get install -y libsqlite3-dev
apt-get install -y libxml2-dev
apt-get install -y libxslt1-dev
apt-get install -y autoconf
apt-get install -y libc6-dev
apt-get install -y libncurses5-dev
apt-get install -y automake
apt-get install -y libtool
apt-get install -y bison
apt-get install -y pkg-config
apt-get install -y libmysqlclient-dev
apt-get install -y libpq-dev
# rvm
curl -L get.rvm.io | bash -s stable --auto
source /etc/profile.d/rvm.sh
# ruby
rvm install 2.0.0
rvm --default use 2.0.0
# ruby on rails
gem install rails -v 4.0.0
# compass sass
gem update --system
gem install compass
# nodejs
touch /home/vagrant/.npmrc
mkdir /home/vagrant/.local
chown vagrant:vagrant /home/vagrant/.npmrc
chown vagrant:vagrant /home/vagrant/.local
echo "root = /home/vagrant/.local/lib/node_modules" | tee -a /home/vagrant/.npmrc
echo "binroot = /home/vagrant/.local/bin" | tee -a /home/vagrant/.npmrc
echo "manroot = /home/vagrant/.local/share/man" | tee -a /home/vagrant/.npmrc
cd /home/vagrant/.local
wget "http://nodejs.org/dist/v0.10.16/node-v0.10.16.tar.gz"
tar xf node-v0.10.16.tar.gz
rm node-v0.10.16.tar.gz
mv node-v0.10.16 node
cd node
./configure --prefix=/home/vagrant/.local
make
make install
cd /home/vagrant
ln -s .local/lib/node_modules .node_modules
chown vagrant:vagrant /home/vagrant/.node_modules
echo 'PATH=/home/vagrant/.local/bin:$PATH' | tee -a /home/vagrant/.bashrc
# java and ant
apt-get install -y openjdk-7-jre
apt-get install -y openjdk-7-jdk
apt-get install -y ant
# cleanup
apt-get autoremove -y
apt-get update
apt-get upgrade -y
# create virtual host
function make_vhost
{
cat <<- __EOF__
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost
DirectoryIndex index.html index.htm index.php
DocumentRoot /vagrant/public
<Directory /vagrant/public/>
Options Indexes FollowSymlinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
ErrorLog /vagrant/.logs/error.log
CustomLog /vagrant/.logs/access.log combined
</VirtualHost>
__EOF__
}
# create directories
mkdir -vp /vagrant/.logs
mkdir -vp /vagrant/public
# log files
touch /vagrant/.logs/error.log
touch /vagrant/.logs/access.log
# set default virtual host
make_vhost > /etc/apache2/sites-available/default
service apache2 restart
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.provision :shell, :inline => "echo \"America/Chicago\" | sudo tee /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata"
config.vm.provision :shell, :path => "vagrant.sh"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :forwarded_port, guest: 443, host: 8443
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network :private_network, ip: "192.168.33.10"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment