Skip to content

Instantly share code, notes, and snippets.

@esparta
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esparta/99a3857d9cc7a42692cc to your computer and use it in GitHub Desktop.
Save esparta/99a3857d9cc7a42692cc to your computer and use it in GitHub Desktop.
MetroLogos in development (using Vagrant)

These are the steps for a minimal development box for Metrologos.

Requirements

I'm going to use a virtual machine with VirtualBox using Vagrant, so you must install them beforehand. Also, it will need the hashicorp/precise32 box (will be downloaded if not present), if you want to use other debian-compatible, change the Vagranfile according.

As we are going to install ubuntu packages, you'll need some kind of internet access (if a 33.6 Kbps dial-up it's OK for you, it's OK for me)

Instructions

1.- Clone Metrologos (or your fork)

git clone git@github.com:beco/MetroLogos.git 

2.- Create a Vagrant machine into your repository folder

cd MetroLogos
vagrant init

3.- Download the files to boot-up your Vagrant Machine

wget -O Vagrantfile https://gist.githubusercontent.com/esparta/99a3857d9cc7a42692cc/raw/Vagrantfile
wget -O bootstrap.sh https://gist.githubusercontent.com/esparta/99a3857d9cc7a42692cc/raw/bootstrap.sh

4.- Start your Vagrant machine

vagrant up

All the above steps will do the following:

  • Create a new virtual machine in VirtualBox
  • Mount a directory en the VM called /metrologos , poiting to the local ./src directory
  • Update the VM's repositories (based on Ubuntu 12.04) via apt-get update
  • Install the minimal packages for a working MetroLogos (checkout in bootstrap.sh):
    • Install nginx-light (the reduced version of nginx)
    • Download a minimal nginx configuration file (I'm lazy, sorry)
    • Install php5-fpm & php5-gd
  • Do "port forwarding" to the VM's web application.

From now on you can browse the MetroLogos application on your development box: http://localhost:8080

Any changes you do in the development directory (./src/*) will be available on the VM.

## boostrap.sh
## For use in MetroLogos deployment
## https://github.com/beco/MetroLogos
#Proxy aware
# just set the http_proxy environment variable on your dev machine
if [ ! -z $1 ]; then
## We have a proxy...
BASH_FILE=/home/vagrant/.bashrc
proxy=$1
# First, the bash environment variable
echo "Configuring proxy: $proxy"
export http_proxy=$proxy
export https_proxy=$proxy
## Make it permanent (on vagrant's profile)
echo "export http_proxy=$proxy" >> $BASH_FILE
echo "export https_proxy=$proxy" >> $BASH_FILE
## Config the apt file for the apt-get update
echo "Acquire::http::proxy \"$proxy\";" >> /etc/apt/apt.conf
echo "Acquire::https::proxy \"$proxy\";" >> /etc/apt/apt.conf
fi
## Update the ubuntu/devian box
echo "Deploying...\n"
apt-get update
apt-get install nginx-light php5-mcrypt php5-fpm php5-gd -y
## Fixing some anoying Bug nginx + VirtualBox
## http://wiki.nginx.org/Pitfalls
## http://jeremyfelt.com/code/2013/01/08/clear-nginx-cache-in-vagrant/
sed -i 's/sendfile on;/sendfile off;/g' /etc/nginx/nginx.conf
echo "Getting minimal nginx configuration file\n"
wget -O /etc/nginx/sites-available/default \
https://gist.githubusercontent.com/esparta/99a3857d9cc7a42692cc/raw/default
service php5-fpm restart
service nginx restart
# Minimal nginx configuration file for Metrologos
# https://github.com/beco/MetroLogos
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /metrologos/;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
# -*- mode: ruby -*-
# vi: set ft=ruby :
## Vagrantfile
## For use in MetroLogos deployment
## https://github.com/beco/MetroLogos
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "hashicorp/precise32"
config.vm.provision "shell" do |s|
s.path = "bootstrap.sh"
s.args = ENV['http_proxy']
end
# 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
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
config.vm.synced_folder "src", "/metrologos", owner: "www-data", group: "www-data"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment