Sunday, September 28, 2008

Setting up Cake on a custom folder

I wanted to try the PHP framework Cake, but if you look at the documentation it assumes you want to install Cake under the /var/www/html folder.

You can obviously install to other folders, but if not done properly, you'll encounter a start page with no images, no styles, and some error messages.

The steps I took to make Cake work in my folder (/home/me/dev/myapp) and to work with the http://localhost/myapp URL where:

  1. Uncompress the latest version of Cake to /home/me/dev/myapp
  2. Edit my /etc/apache2/users/me.conf and add the following (replace braces with chevrons):
    Alias /myapp/ "/home/me/dev/myapp/"
    {Directory "/home/me/dev/myapp/"}
    AllowOverride All
    Order allow,deny
    Allow from all
    {/Directory}
  3. Edit the .htaccess file in your /home/me/dev/myapp folder and add RewriteBase /myapp/ to it. Should look something like (replace braces with chevrons):
    {IfModule mod_rewrite.c}
    RewriteEngine on
    RewriteBase /myapp/
    RewriteRule ^$ app/webroot/ [L]
    RewriteRule (.*) app/webroot/$1 [L]
    {/IfModule}
  4. Make sure your /home/me/dev/myapp/app/tmp folder is writable by all
  5. Restart apache

And that's it. After these steps you should be able to access your application and see the default Cake page, including images & CSS.

No comments: