PHP
Article

5 Easy Ways to Get Started with PHP on Vagrant

By Aldo Ziflaj

Vagrant is a tool for creating and managing virtual environments that help many developers not have to care about the “works on my machine…” problem. Vagrant creates reusable development systems that can be used again and again, helping you keep your system clean of too many installations.

When you are focused on development and lack the skills of a sys admin, the best thing to do (if you are going to use Vagrant during development) is to try another way of setting up your Vagrant configuration.

When it comes to PHP development, there are some online services that simplify the setup and configuration of these Vagrant virtual machines. Here is a list of some of these services.

1. PuPHPet

PuPHPet is probably the most “famous” of these services, and probably the most “specialized” one of them. It gives you the ability to host the VM on your local machine, on Digital Ocean, Rackspace or Amazon Web Services. You get to add forwarded ports with just a click of a button, and sharing source folders is as easy as that too. You can customize the firewall by setting rules and removing them as needed. As for web servers, you can choose between Apache and Nginx, choosing aliases and ports where to access the application.

When it comes to programming languages, PuPHPet is not all about PHP. Besides PHP, you can choose to install Python, Ruby, NodeJS and HHVM. You can’t install both PHP and HHVM, since the service doesn’t allow this – use Homestead Improved for running both at the same time. When installing HHVM, you can also choose to install the nightly release, which gives you the possibility of testing Facebook’s Hack language.

As for databases, PuPHPet has the biggest repository of those, with 6 different databases available. You can choose between MySQL/MariaDB (can’t have both of them), PostgreSQL, Redis, SQLite and MongoDB. You can chose to install Adminer for DB management, but don’t install it onto the production server.

Before finishing, PuPHPet allows you to install tools like RabitMQ, Elasticsearch, etc.

All that PuPHPet wants from you is that you use a Vagrant version not lower than 1.6. Also, you need VirtualBox in order to use the configurations on your local machine. You can find the source code of PuPHPet on this GitHub repo and a more in-depth guide here.

2. Protobox

Protobox is another online Vagrant service. There are many reasons to use Protobox. It actually started as a fork of PuPHPet, but turned out to be a complete other project, due to some issues related to Puppet (not PuPHPet). Protobox has grown into a great service that helps create Vagrant configurations for web application development.

When using Protobox, you can choose from a list of application types:

You can add more than one of these applications to the configuration. As for the web servers, both Apache and Nginx are available. You can choose only three languages: PHP, HipHop (with HHVM) and Ruby.

At the time of writing this, Protobox supports only MySQL and MariaDB, but other databases, such as PostgreSQL, MongoDB, Redis and Riak are coming soon. Tools such as Ngrok and NewRelic tools (PHP Agent and Node Agent) can be installed by ticking a checkbox.

You can find the source code for Protobox in their GitHub repo.

3. Phansible

Phansible is another tool for creating Vagrant configurations based on Ansible, also inspired from PuPHPet.

Phansible is somewhat simpler than the above services. It allows both Apache and Nginx, with HHVM only when you choose Nginx. You can’t choose any other language than PHP, but you can chose between versions of PHP. Also, you can’t choose any other database other than MySQL.

When you’re predetermined to use only Apache/Nginx, PHP and MySQL, Phansible doens’t differ that much from the other services above. Otherwise, you would have to install other tools manually.

4. Rove

Rove is probably the simplest of them all. You can choose any of the typical configurations, Rails and LAMP, or you can create your configuration manually.

Rove supports CouchDB, MongoDB, MySQL, PostgreSQL, Redis and SQLite as databases. You can select as many as you want of them. It also supports the same languages as PuPHPet, all except HHVM.

5. Customized configurations

There are also some other Vagrant configurations that are case-specific, i.e. for a single PHP framework.

I would mention here Laravel’s Homestead, which makes Laravel development a piece of cake, both front and back end. It comes with PHP5.6, Nginx as the web server, both MySQL and PostgreSQL; and NodeJS, with Bower, Grunt and Gulp for the front-end development. There’s an improved version of Homestead here.

Phalcon also has a Vagrant configuration, which saves you the time of installing it and configuring it in an existent server, although you can follow this quick tip to install Phalcon on a Homestead Improved instance.

WordPress has its own Vagrant configuration, VVV – Varying Vagrant Vagrants. There is a full tutorial on SitePoint which shows you how to use VVV.

Final words

Vagrant may be difficult to use sometimes, but is worth pursuing as it can be exceptionally useful. If you are tired of configuring your machine for every project you have, then Vagrant is the right tool for you. If you face problems while configuring your machine, then using a prepackaged vagrant box is the best answer to your problems. Any alternatives to the services above we’ve missed? Let us know!

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

  • hot_rush

    thanks. seems that puphpet still the best choose

    • Aldo Ziflaj

      PuPHPet and Protobox are the best choices I think

  • sincarne

    While not as configurable as these, http://box.scotch.io is dead simple. I use it, and like it.

  • Aldo Ziflaj

    Never heard of it, but I think that it would be better to configure your vm :-)

    • sincarne

      Maybe for folks who have different needs on different projects. I like the “sane defaults” approach of Scotch Box. I haven’t used it a tonne, but when I have, I haven’t found it lacking. But I’ve never needed to deploy a Scotch Box VM, so maybe in that use case, PuPHPet would be a better option.

  • Aleksander Koko

    Nice article

  • Simon Coulton

    Nice list of Vagrant related tools.

    I’ve put together a collection of Ansible roles and playbooks for this very purpose (which can also be used to provision other servers), https://github.com/simoncoulton/ansible and https://github.com/simoncoulton/vagrant for the relevant Vagrantfile config.

  • Kirill Rakovchuk

    Protobox doesn’t allow setup Redis or ElasticSearch and some other things, for example. But PuPHPet does it. Definitely, PuPHPet is favorite for me.

  • Johnnie Walker

    For Drupal development I found Vagrant Drupal Development (VDD) was really useful in getting started quickly. It sets up the machine for Drupal 7 and Drupal 8. Adds other goodies like a mailcatcher for checking the emails being sent out by the default framework installation process.

    See https://www.drupal.org/project/vdd

  • Liviu Dragulin

    Great article! PuPHPet is a very good choice.

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in PHP, once a week, for free.