Tuesday 22 April 2008

Installing CakePHP into a Subdirectory

CakePHP is designed to be installed into a webroot directory. The .htaccess files are pre-configured to make everything work out of the box ...

... except in my setup. I have installed CakePHP into a subdirectory of my development root. This seems to confound CakePHP - which is possibly due to some Apache settings.

I have my development in a subdirectory of my home:
/home/raymond/dev/workspace
. My Apache configuration sets this as the root for http://localhost/dev/:
Alias /dev "/home/raymond/dev/workspace
<Directory "/home/raymond/dev/workspace">
AllowOverride All
Order allow,deny
Allow from all
</Directory>


I use Eclipse, so this seems to make sense. This means I can have
/home/raymond/dev/workspace/birthclass
for the birthclass site development, and now:
/home/raymond/dev/workspace/cakephp
for the CakePHP experiment. All fairly logical so far ...

... when having followed a tutorial, all I get from Apache is:
The requested URL /home/raymond/dev/workspace/cakephp/app/webroot/ was not found on this server.

After some monkeying around, I have found the trick: edit the .htaccess files. There are three: in the CakePHP root, app and app/webroot. In each case, the RewriteBase must be defined. In my case, these are /dev/cakephp/, /dev/cakephp/app/ and /dev/cakephp/app/webroot/ respectively. So now, my cakephp/app/webroot/.htaccess file look like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dev/cakephp/app/webroot/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

And now I have a fully functioning CakePHP setup in its own subdirectory. When I request http://localhost/dev/cakephp, I get my CakePHP application. When I request http://localhost/birthclass, I get my birthclass application.

Job done. On to the tutorials ...

Starting From the Beginning

This blog will document my explorations into web application development using CakePHP.

My current hosting provides MySQL and PHP on a Linux platform. I can't justify the expense of a server all to myself - even a virtual one. I don't want to have to make sure my server at home is up 27*7 .. so PHP is my language.

I'm fine with this: I have some experience with programming in PHP and have dabbled with Mambo (now Joomla!), Exponent CMS and Drupal. PHP is fairly powerful when it gets going, but is simple enough to knock up code quickly.

Whilst sniffing around the web - reading up on Ruby on Rails as it happens - I stumbled upon CakePHP. I've just completed a custom CMS to back the website I've been maintaining, so this seems an ideal time to see how CakePHP could have made the framework creation simpler.

So ... watch this space.

Oh, and do feel free to correct me and make suggestions!