Running Symfony 2 on a Mac OS X

This article discusses how to set up Symfony 2 on Mac OS X. I’m running a MacBook Pro with OS 10.6.8. The article will aim at succinctly doing what’s necessary to get your system up to date with a version of PHP that will support Symfony 2 and resolve some of the conflicts I received when setting it up on machine.

Mostly, I’m using the article on Symfony’s website to get started. My post here will attempt to bridge a few of the setup gaps.

First updating your php to the latest:

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.4

Your old php will still be under /usr/bin/php. So what I do (which might be a little dangerous) is some symlinking magic:

cd /usr/bin
mv php php.old
ln -s /usr/local/php5/bin/php php

Now, your php will point to the updated version.

After that, you will need to get a copy of composer. Although you can manually install Symfony, composer is a great utility and can help in doing some of the boiler plate work for you. You obtain and install composer by running the following command:

curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin

This will install composer into /usr/bin. This makes composer more universal when dealing with some of the commands. An additional step you can take is symlinking it by doing something like

ln -s /usr/bin/composer.phar /usr/bin/composer

With composer installed, you can begin to grab the Symfony software.

php composer create-project symfony/framework-standard-edition Symfony 2.3.3

That command should download the latest version of Symfony. Run this command from the working directory where you want to run your application. There is a possibility that the system might be able to find composer so you might have to be more explicit by adding /usr/bin/composer.

The getting started documents will encourage you to run the check script to ensure that your system is suitable for Symfony. You will need to do this under you ${APP_HOME}/Symfony directory:

php app/check.php

You’ll see various checks but the one major check I decided to handle is the lack of APC. APC is an OP code cache which will help speed up your Symfony application greatly. Since there’s a good possibility that your Symfony will run in a production environment with something like APC, I decided to include that aspect in my guide:

pecl install apc

It seems that you can run this without sudo/root access. At the end, it’ll mention that you’ll need to add the apc extension into your php.ini file. For the upgraded php 5.4, this file is located under:

/usr/local/php5/lib/php.ini

Just go to the end of the file and add a section like this:

[apc]
extension=apc.so
apc.enabled=1
apc.shm_size=128M
apc.ttl=7200
apc.user_ttl=7200
apc.enable_cli=1

When you re-run your check, the warning for apc no longer will be displayed.

One other warning that you may receive is one concerning xdebug. Since the PHP that ships with Macs have xdebug, for the most part it already should be enabled. However, the problem with this error when you examine your php.ini file is that the entry for setting the nesting level is not present (or too low). The fix is easy as you just need to add the following entry into your php.ini file:

[xdebug]
xdebug.max_nesting_level=250

Something you might notice about this entry is that we do not have the extension defined here. However, if you run a phpinfo() function, you’ll see that xdebug is present. So it’s unnecessary to put the extension= entry here as well.

That should get the basics setup. For coding, etc., I suggest reading the article for getting started on their website.

(Visited 531 times, 1 visits today)

Comments

comments


Posted

in

by

Comments

2 responses to “Running Symfony 2 on a Mac OS X”

  1. Tadek888 Avatar
    Tadek888

    Hello
    When i try to do this
    curl -sS https://getcomposer.org/installer | php — –install-dir=/usr/bin

    i have 3 times permision denied
    Could not create file /usr/bin/composer.phar

  2. keithyw Avatar
    keithyw

    You might have to run it like:

    sudo curl -sS https://getcomposer.org/installer | php — –install-dir=/usr/bin

    The issue is that since you’re trying to install composer into /usr/bin, you probably do not have sufficient permissions to write into the /usr/bin directory. Try that and let me know if it works.

Leave a Reply