blog and things oh hi there!
A modern PHP development environment

As I was switching to PHP 7, I decided it was a good time try and configure a better development environment.

At work, I am currently using MAMP but at home, I was using a combination of homebrew PHP + MySQL with the default MacOS Apache webserver.

This works extremely well but only downside being that whenever you do an OS upgrade, you basically have to start over and re-configure everything from scratch.

Wanting to move away from this, I narrowed my options down to Docker and Vagrant.

In theory, Docker would be a great choice for this. However, with multiple projects, it was difficult to configure parellel projects as it required having to run multiple docker instances at the same time. On a laptop with limited resources, this was not a good fit.

I ended up going with Vagrant and Ansible to set up a single VM that could host all my projects.

Here is how I set it all up.

Vagrantfile:

# vagrant 1.9.0
Vagrant.configure("2") do |config|

  # select the box you want to use
  config.vm.box = "ubuntu/yakkety64"

  # disable box update check on startup
  config.vm.box_check_update = false

  # forwarded port from host to the virtual machine
  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "forwarded_port", guest: 443, host: 44300
  config.vm.network "forwarded_port", guest: 3306, host: 33060
  config.vm.network "private_network", ip: "192.168.33.10"

  # folder syncing between the host and guest
  config.vm.synced_folder "../Sites", "/home/ubuntu/websites", create: true, type: "nfs", :mount_options => ['actimeo=1,nolock']

  # virtual machine settings
  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id,
      "--memory", "1024",
      "--cpus", "1",
      "--natdnsproxy1", "on",
      "--natdnshostresolver1", "on",
      "--ostype", "Ubuntu_64"
    ]
  end

  config.ssh.forward_agent = true
  config.vm.hostname = "vagrant"

  # provision the box with ansible
  config.vm.provision "ansible" do |ansible|
    ansible.extra_vars = { ansible_ssh_user: 'ubuntu' }
    ansible.verbose = "v"
    ansible.playbook = "bootstrap.yml"
  end
end

Once the LEMP stack is all set up and configured through Ansible, I simply symlink the nginx virtual hosts to sites-enabled and access them through the host machine by editing the hosts file on (MacOS) /etc/hosts:

192.168.33.10 project.dev www.project.dev
© 2019 Kevin Jung