Ask Your Question

puppetlabs/apache with Vagrant and PHP

asked 2014-08-20 07:18:48 -0600

amcsi gravatar image

updated 2014-08-20 09:02:48 -0600

I saw that there's an official puppet module by puppetlabs for making Apache related tasks easier (especially the fact that you can set up different vhosts easily).

I develop PHP applications and I've been looking around a lot for solutions to be able to develop under an environment fairly accurate to the production server with the help of Vagrant. The issue I've seen so far when looking at solutions like PuPHPet (by itself at least) or Ansible was that although they support development on a VM accurate to the live server, it only really supports 1 project per server; so the entire server would be dedicated to that one project which is not okay.

I was hoping for a way to use Puppet because of its customizability, and combine it somehow with Vagrant to be able to develop projects one by one on their own virtual machines, but have them all be deployed to a single production server using a different vhost for each application, having all PHP and Apache dependencies installed for all of the projects there; however for each individual project I do not want to install anything that is not a dependency of that specific project on its own individual Vagrant machine; I don't want to have to git clone 30 projects every time I run vagrant up just to match what's on the production server when I only want to develop that one application.

The reason behind all this is it would provide myself a means to have all of the following benefits:

  • Reduction of server costs (I don't need a new production vps for every single project; I can hold several projects on one server)

  • Ability to develop in an environment almost similar to that of the production server (with the exception that the "other" projects that would otherwise be on the production server will not be available on the development servers)

  • Lightweight Vagrant installations (you would only need to clone the one git project for that specific project and only install its PHP extension dependencies, rather than everyone's)

  • Most importantly: Easy PHP/Apache version migration (say I've been hosting 30 PHP 5.4 applications on a production server. I decide that I want to start using PHP 5.6 for 10 of those projects. All I would have to do is open a new production server that would have PHP 5.6, change its Puppet files, then make some changes to the Vagrant files for of the 10 projects, and a few other simple things, and bam I upgraded PHP. No more "I would like to upgrade the project to PHP 5.6, but it's too much work and is risky, so I won't")

Does this all make sense? I can clarify anything if needed.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-08-20 08:33:08 -0600

We do that the following way:

  1. using the official modules (apache, nginx and some community modules from forge)
  2. created a "website" module to manage the websites (including all data in hiera .yaml's)
  3. created a "vagrant" module to provision the vagrant boxes for our devs. (special dev configs). Vagrantfile:

    node.vm.provision "puppet" do |puppet|
    puppet.hiera_config_path = "vagrant/puppet-data/hiera.yaml"
    puppet.manifests_path    = "vagrant/puppet-data"
    puppet.module_path       = "vagrant/puppet-modules"
    #puppet.options           = "--verbose --debug"
    puppet.facter = {
     "virtual_type" => "vagrant",

in puppet-data/hiera.yaml there is a yaml hash, which includes the "vagrant" module and in the .yaml you can also specify your own modules / settings. (php modules, domains, vhosts etc)

for sure, it needs a lot of time to create the modules. but you'll save a lot more :)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-08-20 07:17:03 -0600

Seen: 638 times

Last updated: Aug 20 '14