Skip to content

Instantly share code, notes, and snippets.

@JoshuaEstes
Last active August 29, 2015 14:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshuaEstes/3310a94cb13aef9295e8 to your computer and use it in GitHub Desktop.
Save JoshuaEstes/3310a94cb13aef9295e8 to your computer and use it in GitHub Desktop.
My goto files for when I initialize a new symfony2 project. It includes bash scripts, composer.json files and a few other things.

README

These are the default files that I will usually start with when setting up a symfony2 project to use vagrant and puppet. I'm putting this readme file here for future updates.

Usage

Make sure the files that end in .sh are executable.

Once the files are all in place, you should only need to run a few commands and your spiffy new VM is up and running.

./install-puppet-modules.sh
vagrant up
./install-dependencies-on-vm.sh

Next just open up your browser to http://127.0.0.1:8080 and enjoy.

Files

Vagrantfile

The base file that is used for booting vagrant.

app/Resources/puppet/composer.json

This will list all of the puppet modules that the application will use. There could be more or there could be less, this is just the default configuration that is used.

app/Resources/puppet/manifests/default.pp

Configures what some of the defaults on the VM are.

install-dependencies-on-vm.sh

This script will ssh into the VM and run some commands to get the box setup. In case you were wondering why the VM is installing the composer dependencies, it's becasue some libraries have requirements set such as ext-mongo and that would be something we want on the VM not on our host machine.

install-puppet-modules.sh

Gets the puppet modules that is used for this.

update-dependencies-on-vm.sh

After some time, you will need to update the dependencies on the machine.

update-puppet-modules.sh

Puppet modules need to be updated, this will take care of that.

Notes

I have experimented with having app/Resources/puppet/composer.lock ignored by git as well as having it in the repository itself. I have found that it is better to have it in the repository so everyone will be using the same versions of the puppet modules.

These scripts come from a lot of trial and error and from watching how other developers interact with these and what they like and don't like. These scripts are also to help new developers get up and running without the need to install and configure web servers or database servers on their local machine.

Please enjoy and I hope you find these as useful as I have.

{
"name": "symfony/puppet",
"license": "MIT",
"minimum-stability": "dev",
"repositories": [
{
"type": "git",
"url": "git@github.com:JoshuaEstes/puppet-php.git"
},
{
"type": "git",
"url": "git@github.com:JoshuaEstes/puppet-nginx.git"
},
{
"type": "git",
"url": "git@github.com:JoshuaEstes/puppet-mysql.git"
}
],
"require": {
"joshuaestes/puppet-php": "*",
"joshuaestes/puppet-nginx": "*",
"joshuaestes/puppet-mysql": "*"
},
"extra": {
"puppet": {
"modules_path": "modules"
}
}
}
####
#
# Puppet manifest for development in vagrant
#
$production_packages = [
'git',
'curl',
'php-apc',
'php5-curl',
'php5-intl',
'php5-sqlite',
'php5-mysql',
'php5-gd',
]
package { $production_packages:
ensure => present,
}
$development_packages = [
'php5-xdebug',
'vim',
]
package { $development_packages:
ensure => present,
}
#exec { "composer":
# path => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/vagrant_ruby/bin",
# creates => "/usr/local/bin/composer.phar",
# cwd => "/usr/local/bin",
# logoutput => true,
# command => "curl -sS https://getcomposer.org/installer | php",
#}
class { 'mysql::client': }
class { 'mysql::server': }
class { 'php': }
class { 'nginx': }
nginx::server { 'symfony':
root => '/var/www/symfony/web',
template => 'nginx/symfony2.erb',
}
###
#
# Please add this to your .gitignore file
#
/app/Resources/puppet/modules/
/app/Resources/puppet/vendor/
/.vagrant/
### ###
#!/usr/bin/env bash
####
#
# This file is used to install the dependencies on the vagrant VM
#
VM_WORKING_DIR='/var/www/symfony'
run_command()
{
echo "[Running command] $1"
vagrant ssh --command="$1"
}
# Download composer
# @see http://getcomposer.org/doc/00-intro.md#installation-nix
run_command "curl -sS https://getcomposer.org/installer | php -- --install-dir=$VM_WORKING_DIR"
# Install Dependencies
# http://getcomposer.org/doc/01-basic-usage.md#installing-dependencies
run_command "cd $VM_WORKING_DIR && php composer.phar install -vv; \
cd $VM_WORKING_DIR && rm -rf app/cache/*; \
cd $VM_WORKING_DIR && php app/console cache:warmup -n -vv; \
cd $VM_WORKING_DIR && php app/console doctrine:database:create -vvv; \
cd $VM_WORKING_DIR && php app/console doctrine:schema:update --force -n -vv; \
cd $VM_WORKING_DIR && php app/console doctrine:fixtures:load -n -vv; \
cd $VM_WORKING_DIR && php app/console assets:install --symlink -n -vv web"
#!/usr/bin/env bash
####
#
# Install puppet modules used for vagrant
#
# Download composer
# @see http://getcomposer.org/doc/00-intro.md#installation-nix
if [ -f composer.phar ]; then
php composer.phar selfupdate
else
curl -sS https://getcomposer.org/installer | php
fi
# Install Dependencies
# http://getcomposer.org/doc/01-basic-usage.md#installing-dependencies
php composer.phar install --verbose --dev --working-dir="app/Resources/puppet" -n
#!/usr/bin/env bash
####
#
# This file is used to install the dependencies on the vagrant VM
#
VM_WORKING_DIR='/var/www/symfony'
run_command()
{
echo "[Running command] $1"
vagrant ssh --command="$1"
}
# Download composer
# @see http://getcomposer.org/doc/00-intro.md#installation-nix
if [ -f composer.phar ]; then
php composer.phar selfupdate
else
curl -sS https://getcomposer.org/installer | php
fi
# Update Dependencies
run_command "cd $VM_WORKING_DIR && php composer.phar update -vv; \
cd $VM_WORKING_DIR && rm -rf app/cache/*; \
cd $VM_WORKING_DIR && php app/console cache:warmup -n -vv; \
cd $VM_WORKING_DIR && php app/console doctrine:schema:update --force -n -vv; \
cd $VM_WORKING_DIR && php app/console assets:install --symlink web"
#!/usr/bin/env bash
####
#
# Install puppet modules used for vagrant
#
# Download composer
# @see http://getcomposer.org/doc/00-intro.md#installation-nix
if [ -f composer.phar ]; then
php composer.phar selfupdate
else
curl -sS https://getcomposer.org/installer | php
fi
# Install Dependencies
# http://getcomposer.org/doc/01-basic-usage.md#installing-dependencies
php composer.phar update --verbose --dev --working-dir="app/Resources/puppet" -n
vagrant provision
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrant 1.5.2
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 80, host: 8080 # nginx
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.synced_folder ".", "/var/www/symfony", type: "nfs"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
config.vm.provision :shell, :inline => "apt-get update && apt-get install puppet -y"
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "app/Resources/puppet/manifests"
puppet.manifest_file = "default.pp"
puppet.module_path = "app/Resources/puppet/modules"
puppet.options = "--verbose"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment