{"id":11,"date":"2006-06-27T08:22:00","date_gmt":"2006-06-27T13:22:00","guid":{"rendered":"http:\/\/www.padizio.com\/blog\/?p=11"},"modified":"2008-11-06T08:15:15","modified_gmt":"2008-11-06T13:15:15","slug":"piece-of-cake","status":"publish","type":"post","link":"https:\/\/www.padizio.com\/blog\/2006\/piece-of-cake\/","title":{"rendered":"Piece of Cake"},"content":{"rendered":"<p>Well, folks, I&#8217;m back from Summer Film with a vengance.  And it&#8217;s time to get down to some programming, so here goes.<\/p>\n<p>We&#8217;ve all heard about Ruby on Rails.   &#8220;It&#8217;s so great,&#8221; they say.  &#8220;Ruby is so simple, and efficient,&#8221; I hear.  &#8220;There&#8217;s a cool <a href=\"http:\/\/poignantguide.net\/ruby\/\">guide that has Foxes<\/a>!&#8221; says some other guy from the back.<\/p>\n<p><!--more--><\/p>\n<p>But I already know PHP.  I like PHP.  In fact, I <span style=\"font-style: italic;\">really<\/span> like PHP.  It has that old-school C style syntax, and yet, it&#8217;s just frustratingly different enough from C to make it enjoyable to code in. (I use 4; 5&#8217;s good too, but I haven&#8217;t bothered to seriously update, because my hosts still use 4 on the majority of their boxes, including the one I&#8217;m on.)<\/p>\n<p>So what great MVC package is there for PHP similar to Rails for Ruby?  Well, there&#8217;s <a href=\"http:\/\/www.phpontrax.com\">PHP on Trax.<\/a>  A plus is that it fairly closely follows Rails.  But, it requires PHP 5.  Hmm.  Yeah.  5&#8217;s great, but no thanks right now.<\/p>\n<p>There&#8217;s also <a href=\"http:\/\/taniphp.dumitrup.com\/\">TaniPHP<\/a>, which supports PHP 4.  But that&#8217;s not been updated in ages, and it looks like it won&#8217;t be.<\/p>\n<p>And then there&#8217;s <a href=\"http:\/\/cakephp.org\">CakePHP<\/a>.  PHP 4 support, check.  Inspired by Rails, check.  Good documentation, check.  Active community, check. Fantastic.<\/p>\n<p>So here&#8217;s my adventure installing CakePHP on Mac OS X.  You can follow along, if you like.<\/p>\n<p><span style=\"font-weight: bold;\">Step Zero:<\/span><br \/>\nInstall PHP and MySQL for OS X.  I did this a long time ago, but if you&#8217;re just getting started, you&#8217;ll probably like to do this.  Otherwise, things are really not going to make sense later.  There are great instructions for installing PHP &amp; MySQL by hand on <a href=\"http:\/\/developer.apple.com\/internet\/opensource\/php.html\">Apple&#8217;s Developer Connection<\/a>, but I&#8217;m not setting up a production box, I&#8217;m setting up a development box.  For that, I do things the easy way.  I&#8217;ll optimize later.<\/p>\n<p>So here&#8217;s the easy way: Marc Liyanage&#8217;s <a href=\"http:\/\/www.entropy.ch\/software\/macosx\/\">OS X Packages<\/a>.  Easy, helpful, just follow his instructions.<\/p>\n<p><span style=\"font-weight: bold;\">Step One:<\/span><br \/>\nDownload and unzip Cake.  Because I&#8217;m developing multiple Cake apps, I&#8217;m going to put the resulting directory in my \/Library (that&#8217;s Root Library.  Not the User or System Library.)  On most Unix systems, a shared Cake install goes to \/usr\/lib.<\/p>\n<p>The latest stable version at the time of this writing is 1.1.5.3148.  Go ahead and download it from <a href=\"http:\/\/cakeforge.org\/frs\/?group_id=23&amp;release_id=108\">CakeForge<\/a>.  Once you&#8217;ve unzipped it, rename the resulting folder &#8220;Cake&#8221; and move Cake to \/Library.  Now you&#8217;ll have your Cake Libraries installed in \/Library\/Cake.  Recursively delicious.<\/p>\n<p><span style=\"font-weight: bold;\">Step Two:<\/span><br \/>\nIt&#8217;s likely you want to work on your Cake application somewhere other than \/Library.  And you probably don&#8217;t feel like modifying httpd.conf either.  So good news &#8211; you can simply move the \/Library\/Cake\/app folder wherever you feel like working &#8211; and name it whatever you like.  You can also duplicate this folder and create <span style=\"font-style: italic;\">multiple<\/span> Cake apps.  I simply put it in my home directory.  Thus, I end up with \/Users\/myhomedir\/app.  If I want to start a blog application (like the <a href=\"http:\/\/manual.cakephp.org\/chapter\/18\">tutorial app<\/a>, for example) I&#8217;ll duplicate that folder and rename it &#8216;blog.&#8217;  I can duplicate this folder over and over to create my applications.<\/p>\n<p><span style=\"font-weight: bold;\">Step Three:<\/span><br \/>\nNow that you have your library and applications folders in place, you need to move Cake&#8217;s webroot directory into the place where you want to serve your files from.  For example, when you activate Personal Web Sharing, the Apache serves files from \/Library\/WebServer\/Documents.  If I move \/Users\/myhomedir\/app\/webroot to \/Library\/WebServer\/Documents\/webroot, then my Cake application will be accessible at http:\/\/localhost\/webroot\/.  If I copy the <span style=\"font-style: italic;\">contents<\/span> of app\/webroot, to \/Library\/WebServer\/Documents, then my Cake app will simply serve out of http:\/\/localhost.<\/p>\n<p>I like working out of my home directory, though.  Fortunately, Personal Web Sharing also enables the Sites folder of my home directory to serve files: http:\/\/localhost\/~myhomedir\/.  Using the blog example, I&#8217;ll typically move the webroot folder (in \/Users\/myhomedir\/app) to \/Users\/myhomedir\/Sites, and then rename it &#8216;blog.&#8217;  Now, my Cake blog will be served from http:\/\/localhost\/~myhomedir\/blog\/.  Flexible, and handy.<\/p>\n<p><span style=\"font-weight: bold;\">Step Four:<\/span><br \/>\nNow all your files are in place.  To give Cake a working install, though, you&#8217;ll need to tell it where your libraries and app files are!<\/p>\n<p>Going back to the blog example, let&#8217;s review:<br \/>\nMy Cake Libraries are in \/Library\/Cake.<br \/>\nMy Application Folder is \/Users\/myhomedir\/blog.<br \/>\nMy Application Webroot is \/Users\/myhomedir\/Sites\/blog.<\/p>\n<p>First, modify the index.php file in your webroot. Look for the comment box that talks about Cake being installed in a directory layout different from it&#8217;s distribution.  Modify the code like so:<\/p>\n<pre class=\"code\">\/**\r\n* These defines should only be edited if you have cake installed in\r\n* a directory layout other than the way it is distributed.\r\n* Each define has a commented line of code that explains what you would change.\r\n*\r\n*\/\r\nif (!defined('ROOT')) {\r\n  \/\/define('ROOT', 'FULL PATH TO DIRECTORY WHERE APP DIRECTORY IS\r\n               \/\/LOCATED DO NOT ADD A TRAILING DIRECTORY SEPARATOR';\r\n  \/\/You should also use the DS define to seperate your directories\r\n  \/\/define('ROOT', dirname(dirname(dirname(__FILE__))));\r\n  define('ROOT', DS . 'Users' . DS . 'myhomedir');\r\n}\r\nif (!defined('APP_DIR')) {\r\n  \/\/define('APP_DIR', 'DIRECTORY NAME OF APPLICATION';\r\n  \/\/define('APP_DIR', basename(dirname(dirname(__FILE__))));\r\n  define('APP_DIR', 'blog');\r\n}\r\n\/**\r\n* This only needs to be changed if the cake installed libs are located\r\n* outside of the distributed directory structure.\r\n*\/\r\nif (!defined('CAKE_CORE_INCLUDE_PATH')) {\r\n  \/\/define ('CAKE_CORE_INCLUDE_PATH', FULL PATH TO DIRECTORY WHERE\r\n        \/\/CAKE CORE IS INSTALLED DO NOT ADD A TRAILING DIRECTORY SEPARATOR';\r\n  \/\/You should also use the DS define to seperate your directories\r\n  \/\/define('CAKE_CORE_INCLUDE_PATH', ROOT);\r\n  define('CAKE_CORE_INCLUDE_PATH', DS . 'Library' . DS . 'Cake');\r\n}<\/pre>\n<p>Now Cake knows where to find it&#8217;s library and application files.<\/p>\n<p>All that&#8217;s left is to setup the database connection.  Easy peasy:  go to the application directory (\/Users\/myhomedir\/blog).  You&#8217;ll see a &#8220;config&#8221; folder.  Within that folder, duplicate &#8220;database.php.default&#8221; and rename the copy database.php.  Open up this file in your text editor of choice (I like <a href=\"http:\/\/jedit.org\">jEdit<\/a> as far as programming, by the way).<\/p>\n<p>Cake is nice in that you can be simultaneously running a few databases in order to have a &#8216;testing&#8217; environment and a &#8216;default&#8217; environment.  Since this is just a development box, I generally just modify the default array.  For this setup, you need only change the &#8220;login&#8221;, &#8220;password,&#8221; and &#8220;database&#8221; values to their appropriate MySQL values.  For example:<\/p>\n<pre class=\"code\">\r\nvar $default = array('driver' => 'mysql',\r\n      'connect' => 'mysql_connect',\r\n      'host' => 'localhost',\r\n      'login' => 'mymysqluser',\r\n      'password' => 'foxessuckoknotreally',\r\n      'database' => 'blog',\r\n      'prefix' => '');\r\n<\/pre>\n<p><span style=\"font-weight: bold;\">Step Five:<\/span><br \/>\nStart coding!<\/p>\n<p>That&#8217;s all there is to it.  You&#8217;re ready to code up the Blog tutorial, or start your own application.  And a big plus is that for any major Cake changes, you can just install the new libraries into \/Library\/Cake, without having to change your application code!<\/p>\n<p>Out.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well, folks, I&#8217;m back from Summer Film with a vengance. And it&#8217;s time to get down to some programming, so here goes. We&#8217;ve all heard about Ruby on Rails. &#8220;It&#8217;s so great,&#8221; they say. &#8220;Ruby is so simple, and efficient,&#8221; &hellip; <a href=\"https:\/\/www.padizio.com\/blog\/2006\/piece-of-cake\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-11","post","type-post","status-publish","format-standard","hentry","category-code"],"_links":{"self":[{"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/posts\/11","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/comments?post=11"}],"version-history":[{"count":1,"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":53,"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/posts\/11\/revisions\/53"}],"wp:attachment":[{"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/media?parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/categories?post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/tags?post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}