Set up a Complete PHP Environment on Linux with Vagrant

September 10, 2013

PHP

Guest Post by Ran Argaman

This post will explain how to install a fully functional Linux PHP environment using Vagrant and Oracle’s VirtualBox on a windows host machine.

“Host” stands for the machine that the virtual machines are running on, not necessary to be a physical machine. We will use Microsoft’s Windows 7 on this example.

Linux virtual environments on Windows is a very good solution for developers who wants to enjoy the benefits of both worlds.

The powerful and scalability of the Linux and open source in general and the “normal” UI of Microsoft.

The first step is to download and install VirtualBox (https://www.virtualbox.org) and Vagrant (http://www.vagrantup.com). The next step is to create your Virtual Machine using Vagrant.

My suggestion is to create a folder that will contain all your VMs, something like c:\vms

Now, let’s create a new directory, for this example I’m going to use c:\vms\zsdev1
cd into this folder and run the following command:

vagrant init

Now, we have to add a new “Box” instance.

My suggestion is to download the box file to your hard drive and not to download every time you create a VM.

You can download all flavors of Linux from Vagrant servers. For this example I’m going to use Ubuntu Precise32 (http://files.vagrantup.com/precise32.box). Download it to c:\vms\precise32.box.

Now, it our new Vagrant folder (c:\vms\zsdev1) run the following command:

vagrant box add zsdev1 c:\vms\precise32.box

Now open the c:\vms\zsdev1\Vagrantfile and edit as follow:
Change the “config.vm.box” value from “base” to “zsdev1″ and uncomment the following line:

config.vm.network :private_network, ip: “192.168.33.10″

You can of course choose any other IP addess you want for your VM, just remember that if you are running more than one VM you have to give them different IP addresses and don’t confuse the vagrant SSH ports and the private network IPs.

Now let’s boot our new VM:

vagrant up

If you don’t know how to connect you can use the “vagrant ssh” command.

You can find more details and troubleshooting scenarios regarding Vagrant on http://www.vagrantup.com.

Remember that when you connect to Vagrant provisioned VM you have to connect to 127.0.0.1 and use a “special” port like 2222 or 2200 and not to the private IP we configured before.

After connecting to the VM using SSH (putty or any other SSH client), let’s download and install Zend Server 6.1

On your home folder run the following commands:

vagrant@precise32:~$ wget http://downloads.zend.com/zendserver/6.1.0/ZendServer-6.1.0-RepositoryInstaller-linux.tar.gz
vagrant@precise32:~$ tar zxf ./ZendServer-6.1.0-RepositoryInstaller-linux.tar.gz
vagrant@precise32:~$ cd ./ZendServer-RepositoryInstaller-linux/
vagrant@precise32:~/ZendServer-RepositoryInstaller-linux$ sudo ./install_zs.sh 5.4

Now you can open your Zend Server GUI on https://192.168.33.10:10082/ or http://192.168.33.10:10081/

That’s it!

The virtual machine we created is almost the same as a physical Linux machine so you can add MySQL, Mongo or any other database software and you can have your LAMP stack up in a few minutes.

One Response to “Set up a Complete PHP Environment on Linux with Vagrant”

Leave a Reply

You must be logged in to post a comment.