dab.io

Install Symfony on OS X Mavericks

Mavericks is out and my manual for getting Symfony to run on Mountain Lion is already outdated. This guide is an update to the old manual.

Fresh installed Mavericks

Apples newest version of OS X ships with a newer, but still not the latest stable version of PHP:

$ php -v
PHP 5.4.30 (cli) (built: Jul 29 2014 23:43:29)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

We start again with downloading the latest version of Xcode from the Mac App Store.

After installing, get the Command Line Developer Tools through the following command and follow the on-screen instructions.

$ xcode-select --install

Homebrew

We need to get Homebrew. Paste that at your terminal prompt.

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

Run brew doctor to finish the installation of homebrew.

Database

Which database you want to use is up to you. Sadly PHP on Mavericks does not ship with PostgreSQL support, so I need to drop my preferred solution using Postgres.app.

I will use MariaDB, which is an enhanced, drop-in replacement for MySQL. The installation with Homebrew is quite easy:

$ brew install apple-gcc42
$ brew install mariadb

The brew install apple-gcc42 command is needed because Mavericks does not ship with any compiler needed for installing MariaDB.

Start your fresh MariaDB with mysql.server start and test your connection with mysql -uroot. If you get a warm welcome, everything works as expected. Terminate the connection with \q.

PHP

To use php.ini we need to activate it through copying it to /etc/php.ini.

$ sudo cp /etc/php.ini.default /etc/php.ini

Now open the file in your favorite editor, search for date.timezone and add your timezone.

date.timezone = Europe/Berlin

Choose your timezone accordingly and do not forget to remove the ; in front of the line.

Symfony

We are using Composer to install Symfony:

$ cd
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer

Now get the latest Symfony version with:

$ composer create-project symfony/framework-standard-edition symfony/ "2.5.*"

Answer the questions you get asked accordingly to your configuration (I just press enter as the prefilled settings are fine for my configuration). You also might need to replace 2.4.2 with the current version of symfony.

Don’t forget to set the writing permissions to the cache and log directories.

$ cd symfony
$ chmod 0777 app/{cache,logs}
$ chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/{cache,logs}

Start the built-in web server.

$ php app/console server:run

The URL for your application will be localhost:8000/app_dev.php.

Start site of a newly installed symfony

Check if symfony complains about some missing extensions with localhost:8000/config.php.

Config script

Mine is missing the intl and APC extension which I install through PECL or PEAR.

Stop the built-in server with ctrl-c.

PECL and PEAR

Mavericks ships with PECL and PEAR, but we need to activate both:

$ sudo php /usr/lib/php/install-pear-nozlib.phar
$ pear config-set php_ini /private/etc/php.ini
$ pecl config-set php_ini /private/etc/php.ini
$ sudo pear upgrade-all
$ sudo pear channel-update pear.php.net
$ sudo pecl channel-update pecl.php.net

Start installing intl:

$ brew install autoconf icu4c
$ sudo pecl install intl

When asked for the path to the ICO libraries and headers, answer with /usr/local/opt/icu4c.

And now APC:

$ brew install pcre
$ sudo ln -s /usr/local/include/pcre.h /usr/include/
$ sudo pecl install apc

I answered all questions while the install process with the default answers (just pressed enter).

Start the server again php app/console server:run and head over to localhost:8000/config.php to see if our warnings are gone.

Config script done

None? Well, we are done. You can start configuring and developing your application.

Xdebug

If you like to add Xdebug support, just add the following lines to your /etc/php.ini and restart your development server.

zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so
xdebug.remote_enable=On