Skip to content

Instantly share code, notes, and snippets.

@bergantine
Last active November 18, 2021 12:11
Show Gist options
  • Save bergantine/8964657 to your computer and use it in GitHub Desktop.
Save bergantine/8964657 to your computer and use it in GitHub Desktop.
Vagrant config for Apache + mod_ssi

Initial setup of Vagrant Base

This step only ever needs to be done once. Once the precise64 box is installed on a system the remaining steps refer to that same box regardless of the project.

Download and install Xcode from the Apple App Store.

Download VirtualBox from http://www.virtualbox.org/wiki/Downloads, install dmg.

Download Vagrant 2 or higher from http://downloads.vagrantup.com/, install dmg.

Launch a Terminal window, check that it installed:

(host) $ which vagrant

Add a Vagrant box (we'll be using Ubuntu Precise Pangolin (12.04 LTS) 64-bit):

(host) $ vagrant box add precise64 http://files.vagrantup.com/precise64.box

Starting a New Project

Make a directory for the project and change to it, replacing <path_to> with the path to the project and <project_name> with the name of the project.

(host) $ mkdir <path_to>/<project_name> && cd $_

For example, to create a project called 'website' in your home directory:

(host) $ mkdir ~/website && cd $_

When you're all done, this directory will match up with /vagrant/ in the virtual envirionment. Virtualbox keeps the two directories in sync so changes to one will be made in the other.

Copy in the Vagrantfile.

(host) $ curl https://gist.github.com/jbergantine/8964657/raw/Vagrantfile > Vagrantfile

Copy in the provisioning files.

(host) $ curl https://gist.github.com/jbergantine/8964657/raw/bootstrap.sh > bootstrap.sh
(host) $ curl https://gist.github.com/jbergantine/8964657/raw/default > default
(host) $ curl https://gist.github.com/jbergantine/8964657/raw/dir.conf > dir.conf

Startup Vagrant and provision the Virtual Machine:

(host) $ vagrant up

SSH in to the virtualbox:

(host) $ vagrant ssh 

Smoke test

Open a Web browser and navigate to http://localhost:8080. You should see an HTML page with a timestamp.

#!/usr/bin/env bash
apt-get update
# install apache
apt-get install -q -y apache2
# /vagrant is shared by default
# symlink that to /var/www
# this will be the pubic root of the site
# configuration files live at /etc/apache2/
rm -rf /var/www
mkdir -p /vagrant/www
ln -fs /vagrant/www /var/www
################################################################################
# Enable SSI following (mostly) the directions here:
# https://help.ubuntu.com/community/ServerSideIncludes
# Add the Includes module
a2enmod include
# Add Includes, AddType and AddOutputFilter directives
mv /etc/apache2/sites-available/default /etc/apache2/sites-available/default.bak
cp /vagrant/default /etc/apache2/sites-available/default
# To allow includes in index pages
mv /etc/apache2/mods-available/dir.conf /etc/apache2/mods-available/dir.conf.bak
cp /vagrant/dir.conf /etc/apache2/mods-available/dir.conf
# restart apache2
apachectl -k graceful
# smoke test
# open a brower to http://127.0.0.1:8080 to test
echo '<html><head><title>SSI Test Page</title></head><body><!--#echo var="DATE_LOCAL" --></body></html>' > /vagrant/www/index.html
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews Includes
AllowOverride None
Order allow,deny
allow from all
AddType text/html .shtm .shtml
AddOutputFilter INCLUDES .htm .html .shtm .shtml
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm index.shtm index.shtml
</IfModule>
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
# Provision
config.vm.provision :shell, :path => "bootstrap.sh"
# Port forwarding
config.vm.network "forwarded_port", guest: 80, host: 8080
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment