coding-699318_1280

PHP 7 + Apache 2.4 + Ubuntu 14.04

It’s a pretty exciting time in the PHP development world. The release of PHP 7 is just around the corner. Which means now is the time to start testing if sites work with it or not.

Here I’ll walk you through setting up a local server running PHP 7, with Apache 2.4 and Ubuntu 14.04.

Basic box setup

The basis for this adventure will be setting up a Vagrant box. If you haven’t heard of Vagrant, it’s a tool that lets you setup a local development environment that exactly matches whatever you’re going to be deploying to in production, so you don’t run in to any surprises after updating a site.

It requires one of a few different packages to run, but VirtualBox is free and easy, and the way I go.

Than just download the Vagrant installer for your system and you’re ready to get started.

Next you need to generate your config files to get your VM created. puphpet.com is the best way to do this. Just run through their GUI and you can use my config.yaml. One you download their zip file, extract it and the config.yaml file replaces the one in the puphpet folder.

Move the vagrantfile file and puphpet folder to the folder you want to use for development. I have a folder in ~/Documents/development/projects that it’s in. Now from your command line cd to that folder and run the command vagrant up .

That should complete without any errors in 5-10 minutes.

Special fixes to get PHP 7 working

The puphpet script only gets PHP working on the command line, but Apache won’t parse it. We need to make a couple of updates to get that working.

Run vagrant ssh  to ssh into your Vagrant box. Then run sudo su  to give yourself root privileges.

The first step is to edit /etc/mime.types and uncomment the first line related to PHP so Apache knows the correct MIME type. Run nano /etc/mime.types  and search for the first instance of php and remove the # from the beginning of the line, and save your changes.

Next we need to update our Virtual Host file to get php files passed to PHP 7 correctly. Run nano /etc/apache2/sites-available/25-av_n2cgiewscu5e.conf  to edit the file. We need to comment out a few lines, and add in one line after the DocumentRoot line. In the end, it should look like this:

Run service apache2 restart  and it should be up and running for you.

 

The whole process should take less than 20 minutes, and now you can experience PHP 7 for yourself.

Given that PHP 7 is still pre-release it should be noted that this wouldn’t be a good thing to do on a production server, which is why I’ve given instructions for Vagrant here.

Leave a Reply