Setting Up PHP 7 on Mac with Vagrant and VirtualBox (OSX & macOS)

Setting Up PHP 7 on Mac with Vagrant and VirtualBox (OSX & macOS)

PHP 7 – everyone’s talking about it. Curious new operators, fun anonymous classes, performance improvements, it’s everywhere online! I’m quite excited to explore the benefits of the new kid on the block.

In this short tutorial I will walk you through the process of installing and testing out a Vagrant Box and a PHP 7 Installation on your Mac OS X. I use Vagrant as I’d like to keep PHP 7 separate from my own machine until I’m done with porting all my projects over compatibility-wise (I’m looking at you, Mage), so I’m gonna start by installing Vagrant / Virtual Box Setup.

Step 1: Download & Install Virtual Box

Vagrant doesn’t work just on its own, you will need a provider to run the actual machine itself. It’s got built-in support for VirtualBox, so this is the quickest way to go.

Download the package of VirtualBox you need for your OS from here –
I went with OS X Hosts.

Handy Hint:
The latest version right now is 5.2.x and isn’t yet supported by Vagrant – so be sure to go with version 5.1.x or check the requirements first.

Follow the on-screen instructions to install it on your OS.

Step 2: Download & Install Vagrant

Download the application from the Vagrant Website Downloads Page – – again, pick the package according to your OS.

Follow on-screen instructions to install it, fairly straightforward.

Step 3: Set up your First Vagrant Machine

The 2 commands you need to get up and running are:

But wait, don’t get started running these just yet. We’d like to pick the OS we need to create the ‘Box’ environment to work on.

Here’s a list of environments available: Search for the environment you’re looking for – in our case here we’ll go with Ubuntu, namely ubuntu/trusty64.

Click on the link, it will load up a page like this:

Setting Up PHP 7 on Mac with Vagrant and VirtualBox (OSX & macOS)

Click on the “New” Tab under “How to use this box with Vagrant”:

Setting Up PHP 7 on Mac with Vagrant and VirtualBox (OSX & macOS)

Et voila, you will see the necessary commands.

Fire up Terminal on your pc and navigate to the directory where the VM will reside.
I created a directory “vagrant” (Original, I know). cd’ed my way over to it.

Run the command:

This is what you will see:

Once this is done run a quick ls and check the contents of the directory:

A file has been created called “VagrantFile”.
This is the default config file for your box. We need to change a config setting here to be able to access this VM from your local browser.

Open up the vagrant file:

Search for the line:

Uncomment it, and modify the IP to whatever IP address you want, or just leave it as the default as I have done:

Remember this IP address, we’ll need this later.

And then fire up the, well, “up” command

And that’s it! Our machine is up and ready! Lets dive in to the fun stuff now:

Step 4: SSH Into your Machine

SSH’ing into your machine is easy, the command is:

Once you enter this, you will be logged in to the system. Really, that’s pretty much all it takes!

Step 5: Install LAMP Stack

Now that we’ve got our machine, lets begin by installing the LAMP stack.

If you’ve already been developing in PHP before this, you’re already familiar with the steps. I’m gonna go through them briefly here.

Note: If you’re new to PHP, stay tuned for our post on installing LAMP stack.


Check if the installation was fine using: apache2 -v command, you should see this:

Now head over to your browser and enter the IP Address you configured in the Vagrantfile. In my case, it was Here you should see the default apache “It Works!” Page:
Setting Up PHP 7 on Mac with Vagrant and VirtualBox (OSX & macOS)

Awesome! It works! Let’s move on.

Install mysql with the command:

Follow the on-screen instructions, hit return and enter the mysql password whenever asked to. There! You’ve got mysql running too.

Give it a quick test run:

You will be prompted for the password, enter it and you’re now logged in to mysql server.

And now, for the moment we’ve been waiting for. Let’s get our PHP running, shall we. The usual command for installing any PHP version is:

Though, as on this writing, PHP7 is not available for Ubuntu Trusty in the standard Ubuntu repositories so we have to install a repository to our linux distro:

A quick php -v should work here to help you know that everything’s working fine:

And we’re done! You’ve now got a fully functional development environment with LAMP stack right on your machine.

I’m gonna go play around with the cool new PHP7.0 features for now, will write back with my review of the same in a later post.

When I was setting it up the first time around, I pretty much had to install Vagrant boxes a hundred times. A useful command to delete off all boxes is:

It is also possible to install and configure multiple versions of PHP to run on your local setup simultaneously. Here’s a tutorial I’ve found that details the steps for this:


About Rashmi B.

Mostly a startup junkie. Dabbled around in Marketing, SEO, Magento, WordPress, Angular, etc etc. Like to help people bring their startup idea to life. Fan of the Lean Startup movement. Hit me up to know more.

View all posts by Rashmi B.