Multiple PHP versions on OS X

Recently I’ve switched to OSX on my MacBook Air. To keep pace I used XAMPP for first twoo week but today I’ve finally configured my environment as i want.


  • PHP 5.3, 5.4 and 5.5
  • Apache web server
  • Sites in ~/Sites directory
  • Working “localhost” for legacy directory-based projects
  • Different PHP versions for vhosts

Looks simple, but it took me few days to solve all small and big problems.

First what you need is homebrew. On the site you’ll find installation instructions. It’s pretty straight forward.

As an Apache is installed by default in OS X we need install and configure PHP. We want to use different versions per vhost so we’ll use php-fpm.

First we need add dependencies for php-fpm:

Then we can start installing PHPs.

Link operation is linking specific version of PHP to compile paths.

Now when we have installed PHP we need to be able to use them with our default Apache installation. For this we’ll use mod_fastcgi. installation simple as in Debian-ish systems:

Now the funny part with making them work together ;) Most helpful was Gist from diemuzi.

First we need to run three php-fpm in the same time on different ports (I’m using http sockets because.) and set proper user and group for them. Edit this file for each version of PHP you installed.

Second thing is FastCgi configuration for Apache. I’m using Apache 2.2.

Last line includes all .conf files from /etc/apache2/sites-enabled directory. I’m placing there symbolic links to vhosts configured in sites-available directory. Just like you do it in Ubuntu.

Then let’s configure our localhost with PHP 5.4 (Like I said I was using XAMPP so I can live with my webpages in this directory :P)

And sample project with PHP 5.3.

Now when you have domain configured to points to you can see your web directory.

That’s pretty much all. If I’ve forgot about something or something is not clear please leave a comment.

TODO: i need to check how this setup is working with Symfony 2 projects. I’ll write update soon.

UPDATE for Symfony 2

Basic application works fine – copy-paste config once more:


Symbolic links accessible via Samba share

I’m a huge fan of Windows on desktop. We can discuss it all day and night and you can’t convince me that Linux is better on desktop. Mac can be, but this article is not about that. My working environment is a Ubuntu 12.04 accessible via Samba. Recently I had need to have access to my home directory via my default share mapped as Network Disk on Windows. Solutions simple as symlink. Easy at it is Samba didn’t wanted to follow links by default.

Here are three lines which you have to put in your /etc/samba/smb.conf  file under [global]  section:

Restart smbd and it’s done.


Development is not only about code. It’s also environment which helps us work faster and with less stress. In this category I’ll show you my favored tools which I’m using every day.

First is MailCatcher. Simple Ruby/Sinatra application without which I can’t imagine working with emails.

It’s very simple. After installin and run you have virtual, but operating SMTP server. All emails are stored in temporary database and can be viewed from nice and simple web interface. That’s everything, but it’s awesome.

Tip when you are using virtual machine as a development server – set IP to to make web interface available from everywhere.