For the past few days I have been setting up my mac environment and trying to get symfony up and running under the MAMP environment. I thought I would try my hand at a step by step tutorial. Many of the tutorials I found were geared toward people who were familiar with the Mac and/or MAMP. However I wasn’t one of these people.
In this post I will cover how to set up your MAMP and virtual hosts. I am using Mac OSX Leopard so some of this may be different for other versions.
First after installing MAMP, Open MAMP and click on Preferences and then click on the Ports tab. Here click the “Set to Default Apache and MySQL Ports” button. This will change the ports and may require a password to complete.
Next lets download and install symfony. From now on when I refer to the project I will use myproject.
Let’s create a project directory, open up your terminal window and type this (change myproject to your project name)
$ mkdir /Applications/MAMP/htdocs/myproject
/Applications/MAMP/htdocs/myproject will be your web root from now on. Let’s now enter the terminal and checkout Symfony from SVN.
sudo /Applications/MAMP/bin/php5/bin/peardev channel-discover pear.symfony-project.com
sudo /Applications/MAMP/bin/php5/bin/peardev install symfony/symfony
Next in order to use Symfony on the command line let’s add a directory to the $PATH variable on the command line. First we need to check out path, so open up terminal and type this:
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
So we need to take this path and append a ‘:/Applications/MAMP/bin/php5/bin’ on to it so in terminal it will look something like this, but if your path has a different starting configuration it may vary.
$ export PATH=”$PATH:/Applications/MAMP/bin/php5/bin”
Now you should be able to enter symfony commands in the terminal without the full path, you may need to restart the terminal for this to work.
Another way to do this is to just create a symbolic link to the symfony program in your /usr/bin like this:
cd /usr/local/bin
$ sudo ln -s /Applications/MAMP/bin/php5/bin/symfony symfony
So let’s initialize our symfony project
cd /Applications/MAMP/htdocs/myproject
symfony init-project myproject
You will want to create at least one application. From the terminal:
symfony init-app myproject
Next we need to open up the config/config.php in your myproject directory. And change it to something like this:
<?php
// symfony directories
$sf_symfony_lib_dir = '/Applications/MAMP/bin/php5/lib/php/symfony';
$sf_symfony_data_dir = '/Applications/MAMP/bin/php5/lib/php/data/symfony';
?>
Next let’s set up a virtual host with Apache. We need to open up MAMP’s httpd.conf file located at /Applications/MAMP/conf/apache/httpd.conf
We need to add our virtual host information at the very end of this file. Mine looks like this (remember to change myproject to your project name:
NameVirtualHost *
<VirtualHost *>
ServerName myproject
DocumentRoot "/Applications/MAMP/htdocs/myproject/web"
DirectoryIndex index.php
Alias /sf /Applications/MAMP/bin/php5/lib/php/data/symfony/web/sf
<Directory "/Applications/MAMP/bin/php5/lib/php/data/symfony/web/sf">
AllowOverride All
Allow from All
</Directory>
<Directory "/Applications/MAMP/htdocs/myproject/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Now that that is done, we need to edit the /etc/hosts file. So open up terminal again and type:
sudo nano /etc/hosts
Then add 127.0.0.1 myproject to the end of the file. My hosts file looks like this:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
# VIRTUAL HOST START
127.0.0.1 myproject
# VIRTUAL HOST STOP
Next you will want to restart your apache. At this point you should be able to type in your browser
http://myproject
And see the default symfony page.
I usually like to run MySQL from the command line. So next I created a symbolic link to the mysql program into my /usr/bin like this in the terminal:
cd /usr/bin
sudo ln -s /Applications/MAMP/Library/bin/mysql mysql
Then I go into terminal to create my database for my symfony project (remember on MAMP default root password is root.
mysql -u root -p root
mysql >
create database myproject default character set utf8
And then in my project folder /config/databases.yml looks like this:
all:
propel:
class: sfPropelDatabase
param:
username: root
password: root
dsn: mysql://root@localhost/myproject
And that is it. Hope this helped.
I used a few of these articles to figure this all out:
Related posts:
[...] Installing Symfony on MAMP [...]
Hi this is a great resource for people looking to install symfony along with their MAMP install. I went through the trouble of registering just to let other readers know that before you try to view the symfony page in the browser that you should also create a new application within your project using the symfony command: symfony init-app [appname]. Keep up the good work.
Looks great. Good job.
[...] [...]
[...] [...]
[...] First saved by pe3 | 6 days ago links for 2008-08-19 First saved by starsy7 | 11 days ago Installing Symfony on MAMP First saved by mjjna | 14 days ago 3. What does LAMP Stand for? First saved by IraJames | 16 [...]
LAMP = (L)inux, (A)pache, (M)ySQL, (P)HP
I read your posts for quite a long time and must tell you that your posts are always valuable to readers.
Thank’s,
I was looking a good framework to work with mamp, symfony I think is the best option.
Thanks! the steps to configure the web server were spot on. It worked perfectly first time around.
didn’t work first time around for me and about to turn off all the lights and just sit down in the dark whilst pondering what to do with my life…
How can i install a symfony project that has already been created but transfered to me to test etc on to my local machine with MAMP
(i’m running leopard)
thanks for the instructions they worked great with one little exception
when i used
sudo /Applications/MAMP/bin/php5/bin/peardev install symfony/symfony
it installed version 1.0.21
if you use
sudo /Applications/MAMP/bin/php5/bin/peardev install symfony/symfony-1.2.8
“-1.2.8″ being the current stable version – it installs the version number you enter
via – http://www.symfony-project.org/installation/1_2