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.
Requirements
What's Inside
To get started, simply clone the repository using the command
$ git clone https://github.com/alexecus/php-vagrant.git
$ 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
To modify sites hosted by nginx, simple edit the sites.yml
file.
nginx_vhosts:
- 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
nginx_vhosts:
- listen: "80"
server_name: "site.local"
root: "/var/www/html/site"
index: "index.php"
extra_parameters: |
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
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 onlyvagrant nginx
Allows you to provision just nginx, useful for site hosts only changes