Setup Symfony on Mac OS X (using MAMP)

Symfony doesn’t play well with the default OS X server setup, so you will need an alternative setup. This tutorial assumes you are using MAMP but XAMPP is also an option.
This tutorial will get a server up and running that works with Symfony and allow you to access your projects from http://ProjectName.localhost/
Configure Server
- Download the latest version of MAMP. This can take a while.
- Install MAMP
- Allow MAMP’s copy of PHP, PEAR, and MySQL to run from the terminal:
sudo mv /usr/bin/php /usr/bin/php-old
sudo ln -s /Applications/MAMP/bin/php5/bin/php /usr/bin/php
sudo mv /usr/bin/pear /usr/bin/pear-old
sudo ln -s /Applications/MAMP/bin/php5/bin/pear /usr/bin/pear
sudo mv /usr/bin/mysql /usr/bin/mysql-old
sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/bin/mysql
- Symfony can use a lot of memory in the development environment, so you need to edit
/Applications/MAMP/conf/php5/php.inito allow it scripts to use more memory. I changed mine from 8M to 200M.
memory_limit = 200M ;
Set up your project
Either grab a fresh project from the Symfony website or start from your own existing project.
To make sure your project is secure (even if your server isn’t publicly accessible), put the Symfony project files outside your webroot (/Applications/MAMP/htdocs). I put mine in ~/workspace/ProjectName.
Set up a subdomain for this project
To make your project accessible from http://YourProject.localhost/ you must edit your Apache config file.
For the first project you ever add, put this code at the end of /Applications/MAMP/conf/apache/httpd.conf
- Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:80
Listen 127.0.0.1:80
For each project you create, add this section of code with paths modified to reflect the location of your code.
ServerName YOUR_PROJECT_NAME.localhost
DocumentRoot "/Users/YOUR_USER_NAME/workspace/YOUR_PROJECT_NAME/web"
DirectoryIndex index.php
<Directory "/Users/YOUR_USER_NAME/workspace/YOUR_PROJECT_NAME/web">
AllowOverride All
Allow from All
</Directory>
Alias /sf /Users/YOUR_USER_NAME/workspace/YOUR_PROJECT_NAME/lib/vendor/symfony/data/web/sf
<Directory "/Users/YOUR_USER_NAME/workspace/YOUR_PROJECT_NAME/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
For each project, you must also edit the /etc/hosts file and add this line to the end:
127.0.0.1 YOUR_PROJECT_NAME.localhost
Now use the MAMP control panel to restart Apache.
Database
- Note: This section doesn’t apply to those with a fresh project generated by Symfony
If you’re working on a pre-existing project, you need to load in any existing database tables.
Open the file ~/workspace/YOUR_PROJECT_NAME/config/databases.yml and look for a section like this:
all:
propel:
class: sfPropelDatabase
param:
classname: PropelPDO
dsn: 'mysql:host=localhost;dbname=DATABASE_NAME'
username: USERNAME
password: PASSWORD
encoding: utf8
persistent: true
pooling: true
Use phpMyAdmin (located at http://localhost/MAMP/) to create a user with that password. You also need to create a database with that name and assign the user to it.
Now you need to create all the tables for this project and load in any fixtures. Use the terminal to browse to the root of your project directly and run the following commands:
php symfony propel:build-sql
php symfony propel:insert-sql --no-confirmation
php symfony propel:build-all-load --no-confirmation
php symfony cache:clear
NetBeans and Xdebug
I use NetBeans PHP distribution with Xdebug for step-by-step debug support. There is a fantastic tutorial to set up both using MAMP.
The only part of that tutorial that didn’t work was the way php.ini was configured.
First, comment out these lines at the end of /Applications/MAMP/conf/php5/php.ini (by placing a semicolon at the beginning of the line):
[Zend]
- zend_optimizer.optimization_level=15
- zend_extension_manager.optimizer=/Applications/MAMP/bin/php5/zend/lib/Optimizer-3.3.3
- zend_optimizer.version=3.3.3
- zend_extension=/Applications/MAMP/bin/php5/zend/lib/ZendExtensionManager.so
Now add the following lines to the end of the file instead of the ones mentioned in the tutorial:
- Xdebug config for Mac OS X and NetBeans IDE
Also I just skipped the MySQL Administrator program because I prefer to use phpMyAdmin (which comes with MAMP).
Finally, I can’t use normal NetBeans breakpoints to halt the code. I have to place xdebug_break(); on the line that I want it to break on. This is slightly annoying, but having the power of a full debugger is certainly worth this small inconvenience.
Extras:
- Learn how to start MAMP silently (without the control panel window)
- Very detailed guide to setting MAMP up on OS X
- Supercharge your MAMP Environment
Conclusion
You should now be able to access your project from http://YourProject.localhost/
If you’re new to Symfony, here are some resources that will help you out:
- The Definitive Guide to Symfony
- Jobeet Tutorial – A step-by-step tutorial for a real-world project
- Symfony API
If you have any suggestions for improving this tutorial or if you are having any trouble with it, please leave a comment below. Thanks!












Your post is incredibly clear and efficient ! thank you so much !!
Hi!
Thank you for the post. It has been helpful trying to configure my macbook… I found some problems and this is the solution I have found, maybe it could help pther people…
I download the sources of Xdebug and compile (apparently) without problems but my Netbeans keeps forever waiting to establish a connection when I tried to debug PHP. Finally I discovered this page http://aspn.activestate.com/ASPN/Downloads/Komodo/RemoteDebugging and I downloaded a compile version of xdebug.so (with different size…) and it works now with Netbeans and stop in the breakpoints…
But all is perfect, with a big project I didn’t get the debugger to work, but at least it works with some small projects I have tried…maybe the big project has something wrong inside…but as you said: for a full debugger experience its worth this incovenience
Thank you again,
Morris
Thanks for this !
And after your installation, you can help you with this post :
http://blog.jaycreation.net/post/Tutoriel-Symfony-L-aide-indispensable-a-la-creation-d-une-application-Symfony#dossierWeb
Hi,
When i follow the first part of the tutorial:
sudo ln -s /Applications/MAMP/bin/php5/bin/php /usr/bin/php
I get a : Permission denied message when i try to use the php command.
Hey there, I also get the same permission denied message as Toni.