Table of Contents

Multiple apps using one Cake installation

Why?: easier to upgrade the CakePHP libraries for more than one application.

Important note

Wanted to add note to this, not much time to edit the text, but this works if using mod_rewrite also, no changes needed to files. It should be noted this is for development install of CakePHP only, not a recommended production install, DOCROOT should always point to app/webroot in production mode. –phpnut

phpnut's more stable idea

How to do it

I managed to get it to work: (Cake 0.10.0.1076_dev)

Two app folders, each working as webroot and 2 databases:

app1/

app2/

You have to edit (You don’t have to, if you are using mod_rewrite. As mentioned by phpNut):

app1/config/core.php 
app2/config/core.php

Uncomment the line if you don’t have mod_rewrite:

define ('BASE_URL', $_SERVER['SCRIPT_NAME']); 

in both files.

Now you can access these applications from:

http://www.yourdomain.com/cake/app1/

and

http://www.yourdomain.com/cake/app2/

And that’s all. IT WORKS!

Additional Details

Using CakePHP version: 0.10.9.2378_final, and mod_rewrite.

I had some issues with getting the above to work on my web host and its directory structure, so here the steps I did for those that may also run into problems. I should also mention that following the CakePHPManual - Setting Up CakePHP: Production Setup did help me get an idea of how the directory layout should look, although there are some minor differences (see below).

My host provider gives me a home directory and a link to my webroot, and I do not have access for changing the DocumentRoot in apache:

/usr/home/username  (Home dir)
/usr/home/username/public_html -> /usr/www/users/username  (Webroot)

By following the suggested Production setup for shared hosts in the CakePHPManual, I layed out my cake paths as follows:

/usr/home/username/cake  (Cake root - where I extracted the package)
/usr/www/users/username/ (My main site Webroot : copied contents of ~/cake/app/webroot/*)

(Created two additional cake apps...)
%cp -r ~/cake/app ~/cake/app_2
%cp -r ~/cake/app ~/cake/app_yetanotherapp

(...and set up the additional app webroots in my test environment directory.)
/usr/www/users/username/devtest/app2 (App2 : copied contents of ~/cake/app_2/webroot/*)
/usr/www/users/username/devtest/yetanotherapp (App3 : copied contents of ~/cake/app_yetanotherapp/webroot/*)

So basically I wanted a main app for my primary website, and a directory of other cake apps that I would develop and test for clients.

Without doing anything else, I tried navigating my browser to my website, and received the following error:

Fatal error: require() [function.require]: Failed opening required 'cake/bootstrap.php' (include_path='.:/usr/local/lib/php:/usr/www:/usr/www/users/') in /usr/www/users/username/index.php on line 99

The error is due to an incorrect assumption of where the ‘ROOT’ and ‘APP’ paths are in my environment (see lines 45 and 52 in ~/cake/app/webroot/index.php)...Easy enough to fix...

Inserted the following lines in the /usr/www/users/username/index.php (at the top):

define('ROOT', '/usr/home/username/cake');
define('APP_DIR', 'app');
define('CAKE_CORE_INCLUDE_PATH', '/usr/home/username/cake');

The differences from the manual are slight; I had to explicitly set the full path for ‘ROOT’, I ignored the ‘WEBROOT_DIR’ define (as it gave more errors), and added the ‘CAKE_CORE_INCLUDE_PATH’ in order for cake to find its base files.

For the other apps’ index.php files, I added the above defines but changed the ‘APP_DIR’ name from ‘app’ to their respective ~/cake/{app_name}:

# For /usr/www/users/username/devtest/app2/index.php
define('APP_DIR', 'app_2');

# For /usr/www/users/username/devtest/yetanotherapp/index.php
define('APP_DIR', 'app_yetanotherapp');

...and now when I navigate to my website and test apps, it all works beautifully.

Adding additional applications is trivial, and if I need to update my cake release I can do so by overwriting my ~/cake directory. -cgmartin

 
tutorials/multiple_applications.txt · Last modified: 2006/04/13 13:01 by cgmartin