Why use Vagrant instead of XAMPP for local development?

Table of Contents

For all PHP developers, setting up a local environment is a common practice. I had been using XMAPP on my Windows laptop for many years and it really limited me from improving my skills.

  • Using XAMPP means you share environment between all of your projects which leave a lot of potential bugs.
  • Using XAMPP means you save time of setting up environment but create a brick wall to the world of Linux
  • Using XAMPP means you do not practice Linux Commands frequently, even you will never do it when you deploy your website via FTP on a shared host with support control panel
  • Using XAMPP means you do not work on the same system as the production server.
  • Using XAMPP means you will use PHPMyAdmin quite frequently for database administration practices. For my experience, it is not the best practice. it costed me a lot of time importing a large database unsuccessfully for enabling a new project which I could get it done quickly without interruption by using mysql import command.
  • Using XAMPP means you will depend on it for updating any new libraries, updates from the dynamic LAMP communities.
    • Such as testing performance of WordPress or Magento on PHP7

By enabling a Linux Virtual Machine (VM) for local development process, we gain a lot of benefits

  • Setting up the same system as the production server, saving a lot of time for incompatible deployment issues.
  • Have a very big resource of learning from LAMP community, most of questions and answers are for LAMP stack, it saves you ton of time
  • Practice Linux commands everyday and we are getting better and better
  • Update & test a new technology (such PHP7), by simply enabling a new VM
  • Isolate development between projects by enable different VM for each of them
  • You may never get a virus by using a VM
  • For PHP examples, you can try out all PHP versions by just putting them in different VM, that means you can setup a migration project from a legacy PHP code to the latest one easily
  • By creating multiple VMs, we can enable whole architecture of a complex system such as high performance WordPress or ecommerce site where we need
    • A load balancer runs on Varnish or Nginx
    • 2 frontend servers runs on Apache
    • 2 backend servers
    • One master database server and one slave database server
    • Caching using Redis
    • Load static files into RAM

You may never get this done by using XAMPP

And Vagrant was born to make your life with VM extremely easy.

According to vagrant homepage, you will see these introductions

  • Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team
  • To achieve its magic, Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox, VMware, AWS, or any other provider. Then, industry-standard provisioning tools such as shell scripts, Chef, Puppet or Ansible, can be used to automatically install and configure software on the machine.

I will not bother you by more text of “why Vagrant” anymore, you can see more detail in Vagrant.com from its author. I know it is not easy for getting a new stuff or concept. I have built a simple “Hello Vagrant”  project that can help you start working with vagrant in some minutes. Please follow the guide below to see how you can replace XAMPP and old bad habits.

Install Vagrant and VirtualBox on Ubuntu

sudo apt-get install virtualbox
sudo apt-get install vagrant

Install Vagrant and VirtualBox on Windows

  • Download latest version of Vagrant and install it
  • Download latest version of VirtualBox and install it

Install Vagrant and VirtualBox on Mac OS

You can follow this blog to install vagrant on your Mac

Open your terminal and test your vagrant is running

vagrant -v

vagrantv

Install vagrant hostmanager plugin

vagrant plugin install vagrant-hostmanager

Clone hello vagrant project from github

git clone git@github.com:giappv/hello_vagrant.git

Create & Config Virtual Machine

cd hello_vagrant/devops/vagrant
$ vagrant up

You will see this, which is familiar if you install a software on Ubuntu with

apt-get install

ansible_provisioning

After vagrant runs successfully, please visit hellovagrant.dev, take a looks at the screen and more information is there

then you are ready to develop your awesome php projects with Vagrant on Linux environment without using XAMPP anymore.