PHP Vagrant

Develop PHP applications with Vagrant

Development Vagrant PHP

PHP Vagrant is a fast and stable local web environment built using Vagrant and Ansible. Start working on your PHP projects without the hassle of setting up your development enviroment.

There is also a docker port of this stack called PHP Docker which you can check out

The goal of PHP Vagrant is to create a minimalistic development stack that is clean and uses stock modules.


  • Vagrant 1.9.2 and above
  • VirtualBox 5.1 and above

What's Inside

  • Official Centos 7 Box
  • PHP 7.1
  • Composer
  • Nginx
  • MariaDB
  • NodeJS
  • Ruby

Getting Started

To get started, simply clone the repository using the command

$ git clone
$ cd php-vagrant

The next step is to configure the stack by modifying config.yml, the config file contains detailed comment for each configuration entry. The most important part that you need to change is the mount point.

src: ~/my-folder/my-projects
dest: /var/www/html

Make sure that the src point to your local directory that contains all your project's source code.

After setting up the configuration, the you can execute Vagrant. First time provisioning should take a while as Vagrant needs to download the base box and run Ansible to install the components. It usually takes about 15-30 minutes depending on your internet connection.

$ vagrant up

Setting up Nginx

To modify sites hosted by nginx, simple edit the sites.yml file.

  - listen: "80"
    server_name: "site.local"
    root: "/var/www/html/site"
    index: "index.php"
    extra_parameters: "{{ nginx_params_php }}"

The stack also provides aliases for commonly used nginx parameters, such as the nginx_params_php you see above. A complete list of nginx extra parameter aliases can be found on ansible/vars/nginx.params.yml. You can define your own aliases or extend it to your liking.

To define your own nginx parameters, simply omit usage of aliases

  - listen: "80"
    server_name: "site.local"
    root: "/var/www/html/site"
    index: "index.php"
    extra_parameters: |
      location ~ \.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;

Custom Commands

PHP Vagrant also comes ship with custom commands. Whenever you make changes to any configuration, you need to run vagrant provision. Running this command will provision each defined roles. Not too handy if you just want to update the nginx site list.

Custom commands allows you to provision certain sets of roles only, allowing the provisioning to finish significantly faster.

  • vagrant web Allows you to provision all web related roles only
  • vagrant nginx Allows you to provision just nginx, useful for site hosts only changes