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:
. 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

I use Eclipse, so this seems to make sense. This means I can have
for the birthclass site development, and now:
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]

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 ...


Anonymous said...

You have saved me from 2 weeks of wild goose chase...

I was getting /post/index/ not found.. (By the way I am still trying to figure out the "BLOG App" from http://book.cakephp.org/view/219/blog

after fixing the htacess stuff as per your blog I moved to this...


Controller not found but it is there just like the BLOG tutorial...

But if you point your browser to
http://dev.zipmediafactory.com/ I get all the PHpcake stuff so I know it is installed.

my phpcake is installed on


Please help me... what you think
myjeep_2003 AT yahoo dot com

Anonymous said...

Thank you, this was most helpful.

Anonymous said...

This is great!
I do not know why the writers of the CakePHP will think that Cake is the only thing people will have on their server and why they will not think of a production installation option where the application is under a directory not in the root of the domain.

mikeds111 said...

This is absolute genius! This is at least the 10th "guide" I've read on getting stuff to work, and this is the only one that has! Beutiful!

Anonymous said...

This was very helpful! This probably goes without saying, but noobies (like me) should also be sure that their apache server has mod_rewrite enabled. Otherwise the given changes won't take effect.

Qizib said...

Thanks for saving my skin here. I got a test-version online in time because of this tutorial, which surely wouldn't have happened were I to figure it all out by myself.

Anonymous said...

thanks for saving me. for the last 2 weeks I am struggling. Its you by whom i can successfully launch my site.


Souvik said...

Thanks, I was making a silly mistake in my .htaccess. Your post certainly helped me to figure it out where I was going wrong.



Anonymous said...

you saved me! This solution fixed all my problems! thanks for your post!

Anonymous said...


Thank you so much I have been trying to get this to work for so long. Thank you again

peterkr said...

thank you! that was nice trick, saved lot of time!

Anonymous said...

fuck this, going back to Rails....

Fabian 2ki said...

Thanks for this tip!!
You save me for lot of hours attempting to solve this issue.
Thanks again :)

Kamesh Jungi said...

Thx working gud

Sameer said...

Thanks for the instructions. I am new to cakephp. How do I set the RewriteBase in case of WAMP on windows machine.

My project structure is as follows

so I have 3 .htaccess in

So how do I specify path in each of these in this case?

Use absolute path or relative path?

RewriteBase C:/wamp/www/tottler/
RewriteBase C:/wamp/www/tottler/app/
RewriteBase C:/wamp/www/tottler/app/webroot/

in above 3 .htaccess files?

Please help me since rewite of http://localhost/my-some-seo-link-a-html is not rewriting to products/show/$2&%{QUERY_STRING}



Anonymous said...

Thank you so much!

Orly Reznik said...

Thank you so much, seeing my site suddenly come to life, after struggling with the .htaccess file(s), was a great joy.

Anonymous said...

Thanks man :D

Anonymous said...

Thanks Raymond. Your post helped me in fixing the issues with the setup on a windows machine. It took almost 2 weeks and finally found your post.
For me it was an issue with the rewrite base set in .htaccess files.

I am using wamp env. and had set an alias for the project as
Alias /emc "c:/EMC/emcsus/"

#Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all

I had to set the rewritebase as /emc, /emc/app and /emc/app/webroot for C:/EMC/emcsus/.htaccess, C:/EMC/emcsus/app/.htaccess, C:/EMC/emcsus/app/webroot/.htaccess respectively.

Thanks again.

Anonymous said...

I have read your blog and i got a very useful and knowledgeable information from your blog.its really a very nice article.You have done a great job .
Thank you so much
Cake PHP Developmentfor sharing.

Anonymous said...

U just saved me from developing my own MVC....Thanks

Aalap Guruprasad said...

Cakephp is really an amazing e commerce development platform. One must cakephp development for building applications for his business as cakephp development various benefits and features.

friska agustina said...

every time I visit this website I was very interested to read the latest updates from this website .. I'll wait for the latest updates from you. Please also visit my website operatorku , kata kata cinta , kata kata mutiara thank you.

web solution company said...

Thanks raymond, help me to host my website to server

Muhammad Azaz Qadir said...

Why install in sub-directory? I don't get.

Install on main directory. If you need a tutorial for installing CakePHP on server then here is a good tutorial for that: http://www.cloudways.com/blog/install-cakephp-on-cloud/

Debora Marcella said...

Through this post i have learnt about the Installing CakePHP into a Subdirectory which is pretty impressive to see here, keep updating with new post......Webroot Helpline Number | Webroot Toll Free Numbera

Faisal Khan said...

great article for installing cakephp thanx for sharing

Rogers Keira said...

You have done good job on this blog as i have read about the installing CakePHP into a Subdirectory that is really nice to know about it, please keep posing with new halpful blogs......Webroot customer service | Webroot customer care number | Webroot technical support

jewel said...

i am using cakephp version 3 .
my folder path is www/develop
my cakephp is in develop folder and
1 .htaccess is in develop folder
2 .htaccess is in develop/webroot folder

but i can't access my cakephp default page
what should i do??
it is possible because of .htaccess or index.php .
Plz answer me
Thanks you alot

rachael roberts said...

Great Post! you have done a great job. Thanks for sharing it with us. Well done and keep posting CakePHP.

Anika Parker said...

Nice Post!!
We provide all tech services to help the pc users who need help. When problem encounters, you'll be able to decision USA at any instant at our Webroot tech Support Phone Number: +1-800-241-5303(USA/CA) or have chat with our technicians at the same instant. Our technician’s grasp that it's usual to get stuck in between while working on the computers and related devices so we provide Webroot customer Support.
Webroot Customer Support Number
Webroot Technical Support Phone Number
Webroot Support Phone Number
Webroot Help Number
Webroot Customer Service Number
Webroot Toll-Free Number
Webroot Help and Support Number

Digital Marketing Agency nj said...

Thanks for giving me helpful information. this post is help me to put server for our website www.boostrust.com. Great.