Symfony and MAMP

Well, it's the day after Drupalcon 2012. I had the privilege of attending with my coworkers from NewMedia. My head is filled with a dizzying amount of new information and new curiousities.

One topic that seemed to be on many a person’s lips was Dries Buytaert’s announcment that Drupal core will be leaning on Symfony2 for, well, something.

It’s not completely clear to me yet what that something is, though Symfony’s founder, Fabien Potencier, described this holy union at a session during Drupalcon. If you’d like to watch it, here’s a linky —>

As a Drupal developer, this is a rather uncomfortable revelation. In the same breath, it’s an awesome revelation. I’ve been itching to learn more about object oriented php for some time; The ecosystem is rife with php frameworks, and wading through them all is daunting. The decision about which framework to learn just got a lot more simple.

I’ve started fooling around with Symfony2 on my local server. Which happens to be a MAMP server. And it’s not a painless process. I thought I’d describe the steps I’ve gone through to get a working install of Symfony2 under MAMP.

Step 1 - Install php with Hombrew

Now, something interesting about php frameworks is that they rely heavily on cli interactivity to ease the creation of multiple files. You know, that MVC stuff. Not only does MAMP’s php need to meet the requirements for Symfony2, OS X needs an appropriately configured build of php. Let’s knock that out.

I’ve never really liked messing around with the programs that are pre-installed on OS X. I’d rather leave the system more or less pristine, and build myself a nice little sandbox where I can do anything with minimal fear that my computer will explode. Enter Homebrew. Homebrew is a nice little package manager that allows me to install packages like git, ruby, etc… without fear of configuring them and inadvertenly nuking them. Homebrew can be found at –>

Install it. Shit is tight.

Once you’ve got Hombrew installed, open a command prompt(terminal). Type “brew install php” into the prompt… And be disappointed. Turns out php isn’t in the default Homebrew repo. But! As luck has it, there is an alternate repository for brewing php related stuff, and it’s very easy to grab.

Follow the instructions at –> Now you’ve got a whole bunch of brew formulas for php. You’ll need to point brew directly at the package you’d like to install, instead of simply typing “brew install php”. You’ll end up typing something like:

  $ brew install /usr/local/LibraryPHP/Formula/php.rb

Now you’ve got a copy of php to use and mess with, absent of any fear that you might mess up the copy of php that came with OS X. Check that this fresh php install is the php you’re using with your cli by typing “which php” into command prompt.

Terminal should kick back /usr/local/bin/php. If it doesn’t, that’s because of some secret magic that’s happening with your $PATH, and your cli is still finding OS X’s php before it’s finding yours. This is easily fixed with .bash_profile, by basically letting your brew installed packages cut to the front of the line.

Add the following lines to your .bash_profile. If you don’t have a .bash_profile in your home directory, make one:

  # Put /usr/local/{sbin,bin} first

For more on installing php with Homebrew, check out ->

Step 2 - Install intl-php

Now that you’ve got a nice install of php to wreck, type brew install /usr/local/LibraryPHP/Formula/intl-php.rbg into command prompt. intl-php is a library that Symfony2 requires to work correctly. The install takes a little while, so go smoke a cigarette or partake of some similar vice.

Once intl-php is installed, type:

  $ cd /usr/local/Cellar/intl-php/5.3.10/g
  $ open .

You’ll now have a Finder window open, and you’ll see a file called Copy that file. You’re going to add the extension to MAMP’s version of php. Whoosh.

MAMP seems to be undecided as to where things belong. So, find where your copy of MAMP keeps php. My copy of MAMP keeps php at /Applications/MAMP/bin/php/php5.3.6g. You can use Finder to navigate here, or just type:

  $ cd /Applications/MAMP/bin/php/php5.3.6 
  $ open .

You’ll want to add to php’s extensions directory. Mine is at /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626g. Paste here.

Step 3 - Edit php.ini

Okay. Now you’re almost there. You need to edit some php.ini files. php.ini is a file that instructs php how it oughta behave and which modules it should load, amongst other mystical things. You’ll need to edit MAMP’s php.ini, as well as the php.ini that belongs to your Homebrew installed php.

MAMP’s php.ini lives at /Applications/MAMP/bin/php/php5.3.6/confg. Before you edit it, make a backup copy. If you’re not already in the habit of making .bak files of things that you’re not sure what they do, get in that habit. Right now.

Once you’ve got a backup of php.ini, you’ll need to make some edits to the one that php will be using. Find the line that says short_open_tag = Ong and change it to read short_open_tag = Off.

Next, look for the line that reads magic_quotes_sybase = Offg. Below it, add a line that reads magic_quotes_gpc = Off.

Finally, find the “extesions” portion of your php.ini, and add a line that reads extension = intl.sog.

Alright, that’s it. Restart MAMP, and start a new terminal session. You’re ready to install Symfony

Another great article for getting an environment ready for Symfony2 is at –>

Step 4 - Download Symfony2

Now that OS X is warmed up, let’s get crackin’ on a Symfony2 environment. You can grab a Symfony2 package at –>

I use git heavily, and the project page suggests that, if you use git, one should download the “without vendors” package.

If you opt to use the Symfony2 package that doesn’t include vendor libraries, you’ll need to fetch the “Vendors” directory in order for Symfony2 to work. In a command prompt:

  $ cd to/your/Symfony/directory
  $ php bin/vendors install

If you’ve added your Symfony directory to OS X’s hosts file and MAMP’s httpd.conf, you’re ready to start working through the Symfony2 tutorials at –> [

PS - Drush & Stuff

If you’re really fancy, and using drush (you should be), then you’ll be disappointed to know that installing php with Homebrew seems to upset drush. After following the above steps, drush will begin to throw errors. It’s easily fixed, though. All you need to do is make some changes to your Drupal settings.php. In your setup, where it says “localhost”, change this to read “”.