Created by Abraham Broca / @brocakun
Yes, Vagrant, is a configurable lightweight, reproducible, and portable virtual environment.
Virtual Box
Why Virtual box? Simple, because it's free.
$ sudo apt-get install virtualbox
Download the right virtual box version for your OS.
http://www.vagrantup.com/downloads.html
$ wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.6.3_x86_64.deb -O ~/vagrant.deb
$ sudo dpkg -i ~/vagrant.deb
Download the right vagrant version for your OS.
We're very close, we need to enable NFS in order to share files between host and guest (Only UNIX).
$ sudo apt-get install nfs-common nfs-kernel-server
OSX already has the NFS Package installed by default (As far as i know)
Vagrant Plugin system.
Tip: In order to keep the very last version of the vbguest tools install this vagrant plugin.
$ vagrant plugin install vagrant-vbguest
Vagrant UP!
$ cd ~
$ mkdir ~/vagrant-drupal-day
$ cd ~/vagrant-drupal-day
$ vagrant init hashicorp/precise32
$ vagrant up
This is the Ubuntu 12.04/32bits LTS version.
$ vagrant ssh
$ sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions
$ exit
$ vagrant reload
$ vagrant ssh
$ vagrant halt
This will only turn off your Vagrant box and next time you will have to turn it on with the vagrant up command
You can destroy you box with:
$ vagrant destroy
This will completely remove your virtual box installation file, but your vagrant configuration files will not be removed.
Vagrant + Drupal + Solr + Xdebug.
http://renaud-cuny.com/en/blog/2014-02-09-vagrant-drupal-solr-xdebug/
Lets start this again! logout from your recently created vagrant box and lets start another vagrant box
$ git clone https://github.com/rcuny/vagrant-drupal-xdebug-solr ~/vagrant/vagrant-drupal-day-monterrey
$ cd ~/vagrant/vagrant-drupal-day-monterrey
$ sudo chmod 777 /var/www/
$ vagrant up
$ vagrant ssh
$ sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions
$ exit
$ vagrant reload
$ vagrant ssh
$ cd /vagrant; ls
$ git clone --branch 7.x http://git.drupal.org/project/drupal.git d7
OR
$ drush dl drupal --drupal-project-rename=d7
$ cd ~/vagrant/vagrant-drupal-day-monterrey
$ nano Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
## Configuration
# Virtualbox tweaks. See http://docs.vagrantup.com/v2/virtualbox/configuration.html
config.vm.provider :virtualbox do |vb|
# More memory
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
## Network shares.
# UNIX users can use the nfs switch
config.vm.synced_folder ".", "/var/www", :nfs => true
# Windows users SHOULD default to the following settings - See http://docs.vagrantup.com/v2/synced-folders/nfs.html
# config.vm.synced_folder ".", "/var/www"
## Provision
# scripts/provision.sh will provision the box
config.vm.provision :shell, :inline => "
sh /vagrant/scripts/provision.sh;
"
## The Vagrant Box
# Defines the Vagrant box name, download URL, IP and hostname
config.vm.define :vagrant do |vagrant|
vagrant.vm.box = "precise64-apache2-xdebug-solr"
# The following box is stored on a server of mine, feel free to use it directly.
# If you want to rebuild it, check the source repo: https://github.com/rcuny/vagrant-apache2-xdebug-solr
vagrant.vm.box_url = "http://rcuny.li/1dzKD4H"
vagrant.vm.network :private_network, ip: "192.168.66.6"
vagrant.vm.hostname = "vagrant.dcl"
end
end
https://docs.vagrantup.com/v2/vagrantfile/index.html
$ cd ~/vagrant/vagrant-drupal-day-monterrey/scripts
$ nano provision.sh
#! /bin/bash
##### INFO #####
# Provision.sh
#
# This script will provision a clean Vagrant box.
# After provisioning a box, it can be repackaged.
# So that project setup time can be reduced.
#
# Author: Jurgen Verhasselt - https://github.com/sjugge
# Modified by: Renaud Cuny for Boleia - https://github.com/rcuny
##### VARIABLES #####
# Throughout this script, some variables are used, these are defined first.
# These variables can be altered to fit your specific needs or preferences.
# Server name
HOSTNAME="vagrant.dcl"
# Locale
LOCALE_LANGUAGE="en_US" # can be altered to your prefered locale, see http://docs.moodle.org/dev/Table_of_locales
LOCALE_CODESET="en_US.UTF-8"
# Timezone
TIMEZONE="Europe/Paris" # can be altered to your specific timezone, see http://manpages.ubuntu.com/manpages/jaunty/man3/DateTime::TimeZone::Catalog.3pm.html
# PHP settings
MEMORY_LIMIT="256M"
UPLOAD_MAX_FILESIZE="128M"
POST_MAX_SIZE="128M"
# Drush
DRUSH_VERSION="6.2.0" # prefered Drush release from https://github.com/drush-ops/drush/releases
#----- end of configurable variables -----#
##### PROVISION CHECK ######
# The provision check is intented to not run the full provision script when a box has already been provisioned.
# At the end of this script, a file is created on the vagrant box, we'll check if it exists now.
echo "[vagrant provisioning] Checking if the box was already provisioned..."
if [ -e "/home/vagrant/.provision_check" ]
then
# Skipping provisioning if the box is already provisioned
echo "[vagrant provisioning] The box is already provisioned..."
exit
fi
##### PROVISION DRUPAL TOOLS #####
echo "[vagrant provisioning] Installing LAMP stack..."
# Set Locale, see https://help.ubuntu.com/community/Locale#Changing_settings_permanently
echo "[vagrant provisioning] Setting locale..."
sudo locale-gen $LOCALE_LANGUAGE $LOCALE_CODESET
# Set timezone, for unattended info see https://help.ubuntu.com/community/UbuntuTime#Using_the_Command_Line_.28unattended.29
echo "[vagrant provisioning] Setting timezone..."
echo $TIMEZONE | sudo tee /etc/timezone
sudo dpkg-reconfigure --frontend noninteractive tzdata
# Download and update package lists
echo "[vagrant provisioning] Package manager updates..."
sudo apt-get update
# Install Drush
echo "[vagrant provisioning] Installing drush..."
sudo wget -q https://github.com/drush-ops/drush/archive/$DRUSH_VERSION.tar.gz # download drush from github
sudo tar -C /opt/ -xzf $DRUSH_VERSION.tar.gz # untar drush in /opt
sudo chown -R vagrant:vagrant /opt/drush-$DRUSH_VERSION # ensure the vagrant user has sufficiƫnt rights
sudo ln -s /opt/drush-$DRUSH_VERSION/drush /usr/sbin/drush # add drush to /usr/sbin
sudo rm -rf /home/vagrant/$DRUSH_VERSION.tar.gz # remove the downloaded tarbal
##### CONFIGURATION #####
# Changing PHP settings
echo "[vagrant provisioning] Configuring PHP5..."
# Change settings for apache2 PHP
sudo sed -i "s@memory_limit.*=.*@memory_limit=$MEMORY_LIMIT@g" /etc/php5/apache2/php.ini
sudo sed -i "s@upload_max_filesize.*=.*@upload_max_filesize=$UPLOAD_MAX_FILESIZE@g" /etc/php5/apache2/php.ini
sudo sed -i "s@post_max_size.*=.*@post_max_size=$POST_MAX_SIZE@g" /etc/php5/apache2/php.ini
# Change settings for command line interface PHP (used by Drush)
sudo sed -i "s@memory_limit.*=.*@memory_limit=$MEMORY_LIMIT@g" /etc/php5/cli/php.ini
sudo sed -i "s@upload_max_filesize.*=.*@upload_max_filesize=$UPLOAD_MAX_FILESIZE@g" /etc/php5/cli/php.ini
sudo sed -i "s@post_max_size.*=.*@post_max_size=$POST_MAX_SIZE@g" /etc/php5/cli/php.ini
sudo service apache2 restart # restart apache so latest php config is picked up
# Configuring Solr for Drupal
echo "[vagrant provisioning] Configuring Solr for Drupal..."
sudo cp /vagrant/scripts/resources/search_api_solr/solr-conf/4.x/* /opt/solr/collection1/conf/
sudo /etc/init.d/tomcat7 restart
# Hostname
echo "[vagrant provisioning] Setting hostname..."
sudo hostname $HOSTNAME
##### CLEAN UP #####
sudo dpkg --configure -a # when upgrade or install doesnt run well (e.g. loss of connection) this may resolve quite a few issues
apt-get autoremove -y # remove obsolete packages
##### PROVISION CHECK #####
# Create .provision_check for the script to check on during a next vargant up.
echo "[vagrant provisioning] Creating .provision_check file..."
touch .provision_check
https://docs.vagrantup.com/v2/provisioning/index.html
These are a few interesting articles and projects: