Monday 21 May 2012

Configuring CakePHP for an OSX local install


I am currently learning some of the technologies involved in building web based applications, following ideas from the Software as a Service course.

Currently I'm looking at PHP and the CakePHP frameworks.

Obtain the source

Download and unzip the package from the CakePHP website
Rename to a suitable folder, I have put mine in Sites/ScoutCamp.

Set up Apache

Edit your sites file sudo nano /etc/apache2/users/username.conf
   Options FollowSymlinks
   AllowOverride All
   Order allow,deny
   Allow from all

Restart apache sudo httpd -k restart and open a browser to your shared pages.

Lots of errors and messages

First time I fired up the browser I thought “Oh dear me” or at least something along those lines.
Unlike my trial of Ruby on Rails, there were loads of errors and configuration changes that were required.

I have solved most of the problems, but still have one left to suss out.

Timezone settings

In app/Config/core.php there is a line (it was 232 on my build)

   //date_default_timezone_set('UTC');

Uncomment and set to your timezone - Newcastle is in the same timezone as London.


   date_default_timezone_set('Europe/London');

Unable to write 'cake_dev_en-us' to File cache

The app/tmp folder needs to be writable by the web user.
To find out who this is, add the following bit of code to app/View/Pages/home.ctp


   


On my system, the web user is _www, so change the owner:
   sudo chown -R _www app/tmp/

This cleared up all the errors above the title.

Please change the value of “Security.salt” and “Security.cipherSeed”

In app/Config/core.php find the lines and change to a more suitable value. I used sha1sum to generate the salt, and pasted for the salt. The Seed I just typed a few numbers at random.


   df  | shasum

Setting the database connection

You need to create your database using mysql (there are other options, but that's the one I went with).

Copy database.php.default to database.php and add your user and database details. Note that for some reason, OSX will not work user localhost (and that took a day to track down).

   public $default = array(
      'datasource' => 'Database/Mysql',
      'persistent' => false,
      'host' => '127.0.0.1', // Note change from localhost
      'login' => 'ScoutCamp',
      'password' => 'yourPassword',
      'database' => 'ScoutCamp',
      'prefix' => '',
      'encoding' => 'utf8',
   );

URL Rewriting

This is the only bit I haven't worked out yet, but I want to make a start developing my site and will come back to this.



1 comment: