Creating a CakePHP environment using MAMP and OS X
This will show you how to create a CakePHP environment in MAMP on OS X. Here list of softwares used and their version.
- OS X Leopard or Snow Leopard
- MAMP version 1.91 (using PHP5.2.x)
- CakePHP 1.2.8
You shouldn’t have to use MAMP 1.9.1. I have it working on version 1.8.x. You will need to change Apache’s port from 8888 to 80. Make sure there aren’t any other web servers running on the same port. Leave MySQL running on port 8889. We will be creating a /Applications/MAMP/conf/apache/sites file that will store your virtual sites. It isn’t necessary but it’s easier to manage new sites on a separate file. You will need to edit the /Applications/MAMP/conf/apache/httpd.conf file by adding the following lines of code.
# virtual hosts file Include /Applications/MAMP/conf/apache/sites
This will tell Apache to check the new sites file for additional configurations. So now, whenever you need to add or create a new site, you will edit the sites file and add the following code.
<VirtualHost *:80> DocumentRoot /Users/username/Sites/projectname ServerName projectname.local </VirtualHost>
The value of DocumentRoot can be different. I just chose to put it in that folder. Now you will need to edit your /etc/hosts file by adding the following code.
Restart your MAMP server. Now unzip the CakePHP files into the projectname folder. You should now be able to view your new CakePHP site by directing your browser to http://projectname.local. This page will tell you that you need to change the default Security.Salt value. All you need to do is change at least one character and you will meet the requirement. You can also use Terminal to generate your own.
echo -n 'foobar' | openssl sha1
This will give you a 40 character string. You can use a mixture of upper and lower case on the letters. Copy and paste this value from Terminal to give a new Security.Salt value.
The next warning is your database. Rename the database file and edit it. Provide your database server information. Because MySQL in MAMP is using port 8889, you will have to edit the array and add the following.
'port' => '8889'
There are notes in this file to help you further with additional array elements.
To use Terminal with the cake command, you will have to edit you ~/.bash_login file and create aliases. Here is the code to add to your .bash_login file.
# php alias php5="/Applications/MAMP/bin/php5.2/bin/php" # cake for this project alias cake="php5 /Users/username/Sites/projectname/cake/console/cake.php"
You should be able to run
If you get a permission denied error, give it executable access with this.
chmod +x /Applications/MAMP/bin/php5.2/bin/php
That’s it. You can now start baking in a development environment. I know I have skipped a few steps but I’m assuming you know the basic commands and configurations. If not, please feel free to comment and ask questions. I’m still new with the MVC framework and CakePHP so go easy on questions regarding those. I am learning, slowly… haha!
Helpful summary, bookmarked your website for hopes to see more!