title: Building A SOA In PHP Part 1: The Plumbing draft: true tags: - php - soa categories:

- features

In this article I will look at what it takes to build a modern PHP web application. As consumers we are looking for a fast, smooth web experience, with simple and intuitive UIs. This elegant experience should be presented by an equally well designed and tested infrastructure. But as developers how do we achieve that?

In order to make sure we're a good fit, here's a brief summary of the tools and technologies we'll be building on throughout the series:

  • PHP/HHVM
  • Postgres
  • Ubuntu Server 14.04
  • Silex
  • Beanstalk
  • Supervisor
  • Ansible
  • Vagrant
  • Virtualbox
  • Composer
  • Bower
  • Reactjs
  • Bootstrap

From the OS, database, provisioning and dev tools, application code, on down to the front end, a mind boggling amount of technology is involved in today's web. For the purpose of this article, we're going to focus on provisioning tools, OS, and database (vagrant, ubuntu server, and postgres respectively).

Step 1: Repository and Vagrant

Since the example project is hosted on GitHub, the instructions will assume usage of a public GitHub repository.

Install Vagrant here. If unsure about the benefits of using Vagrant, try giving this article a read. Before Vagrant is useful we also needs a provider. For this, install Virtualbox.

Create a new repository, clone it, and initialize a new Vagrantfile inside the project.

$ git clone <your repo> project
...
$ cd project
$ vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

Open up the newly created Vagrantfile. Right next to this line:

config.vm.box = "base"

Add this line:

config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"

The OS of choice is Ubuntu Server 14.04. Ubuntu remains a popular choice for servers, so support is usually easy to find in the community. As an LTS release (long term support), 14.04 makes an exceptional candidate.

Now we can vagrant up and launch a new virtual machine. Great. This new vanilla VM gets us a sandboxed environment. Feel free to experiment and blow things up. Simply vagrant destroy and vagrant up to reset to the last known good state.

Vagrant Provisioner

Vanilla boxes are fun, but not very useful. This tutorial will use Ansible to manage application dependencies (install instructions here).

Ansible has playbooks, which define what software gets installed on the target system. Add a section to Vagrantfile (near the original modification), specifying that it use Ansible to configure newly built VMs.

config.vm.provision :ansible do |ansible|
    ansible.playbook = "ansible/development.yml"
    ansible.verbose = "vvvv"
end

Create a file at ansible/development.yml:

- hosts: localhost
  sudo: yes
  gather_facts: no
  user: vagrant
  vars_files:
    - vars/development.yml
  roles:
    - init
    - php5
    - nginx
    - npm
    - bower
    - composer