Getting CakePHP working in your Home Directory

Written by James McDonald

March 15, 2011

This presumes you know about the security implications of having pages served from you home dir and have taken appropriate precautions to stop unauthorized access:

# add a new directory section to apache

sudo vi /etc/apache2/sites-enabled/000-default
Alias /mapp/ "/home/userme/maps/mapp/"

        Options Indexes MultiViews FollowSymLinks
        AllowOverride All # important to allow .htaccess
        Order deny,allow
        Deny from all
        Allow from ::1/128

# enable mod rewrite in apache

 sudo a2enmod rewrite  && sudo service apache2 restart

# edit the CakePHP access files so they do sensible rewriting.

.htaccess located in Cake Root which in my setup it is /home/userme/maps/mapp/ (this is the directory inside which the CakePHP app, plugins & cake directories are)

   RewriteEngine on
   RewriteBase /mapp/ # add this
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]

.htaccess located in CakeRoot/app/

    RewriteEngine on
    RewriteBase  /mapp/ # add this
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]

.htaccess located in CakeRoot/app/webroot/

    RewriteEngine On
    RewriteBase /mapp/ #add this
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

# remember to restart apache
sudo service apache2 restart

BTW: The above is available in the _very_ good CakePHP Documentation


Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

PC Build

I recently built myself a PC using the SilverStone SG13 Case. I am planning to use it as a Hot Spare. So any client...