Setup a development environment for Symfony on a Mac with Homebrew

Althougha Mac already comes with an apache and php installed, as soon as you’re starting serious development, you’re going to miss a few things.
There are many package manager out there and until now I used MacPorts.
Unfortunately it has a few downsides which led to MySQL crashing and landing in an unusable state. So I decided it’s time for a new installation and a move towards Homebrew instead.

And it turns out, it wasn’t just a good idea but also quite easy. As I still run into a few problems and didn’t really find a good blog entry about it, I took it as a start to write my own one.

Here are the steps it took me to get everything up and running.

Installation

Everything starts with this command line to install Homebrew:

$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

After that we need to install the formulas:

Apache
(https://github.com/djl/homebrew-apache2)

$ brew tap djl/homebrew-apache2
$ brew install djl/apache2/apache22

PHP
(https://github.com/josegonzalez/homebrew-php)

$ brew tap homebrew/dupes
$ brew tap josegonzalez/homebrew-php
$ brew install php54 --with-homebrew-openssl --with-intl

At the moment the intl extension seems to be broken in the formular so
we need to install it “manually”:

$ brew install php54-intl

In addition I recommended APC for Symfony:

$ brew install php54-apc

And mcrypt

$ brew install php54-mcrypt

MySQL

Finally an easy one:

$ brew install mysql

Configuration

Apache

/usr/local/Cellar/apache22/2.2.25/conf/httpd.conf

Set server name to a “real” domain name like

ServerName www.localhost.de:80

Look for index.php file instead of just the index.html file

DirectoryIndex index.html, index.php

Set your own user as user for http process (this is just for convenience and is only for a local development environment)

User YourUser

Remove # at “Include conf/extra/httpd-vhosts.conf” to include the vhost config.

/usr/local/Cellar/apache22/2.2.25/conf/extra/httpd-vhosts.conf

Replace with own vhost config and replace document root of localhost with new path

PHP

/usr/local/Cellar/apache22/2.2.25/conf/httpd.conf

Load PHP5.4 Module:

LoadModule php5_module /usr/local/Cellar/php54/5.4.19/libexec/apache2/libphp5.so

Add php type to mime_module

AddType application/x-httpd-php .php

/usr/local/etc/php/5.4/php.ini

Set timezone

date.timezone = Europe/Berlin

Set higher max execution time

max_execution_time = 600

Set higher memory limit

memory_limit = 512M

Set default charset to UTF-8

default_charset = "UTF-8"

MySQL

Start MySQL on login

$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

Start the environment

Apache

The apache start needs to happen with sudo because only root can bind a process to a port below 1024

$ sudo /usr/local/Cellar/apache22/2.2.25/bin/apachectl start

MySQL

$ mysql.server start

That’s already everything you need to run Symfony on a Mac with all components still under your control.