Cameron
Cameron

Reputation: 28803

CakePHP Shared core for multiple apps

On my local setup I have a load of different CakePHP websites. I'm using a Mac so the folder structure is something like ~/Users/cameron/Sites/sample-website and then within each of these websites I will have the typical Cake folder and App folder.

What I would like to do is have just a core cake folder and then have ALL the sites pull from that one cake core so I don't have the same stuff several times over. I have been reading some tutorials on the web: http://rickguyer.com/cakephp-one-core-many-apps/

So I have my cake folder here: ~/Users/cameron/Sites/cake-1.3/ and then my site here: ~/Users/cameron/Sites/sample-site/ and in this folder I have the usual app folder and htaccess to tell it where to find webroot etc.

Now I have edited the index.php file inside webroot like the tutorial BUT have only changed one line because I haven't moved my files OUTSIDE of the App folder like he does. So the only like I have changed is as follows:

if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
    define('CAKE_CORE_INCLUDE_PATH', '..'.DS.'..'.DS.'cake-1.3');
}

As far as I can tell that is correctly looking two directories up and finding a folder called cake-1.3 however it just gives a error 500?

Any ideas what the problem is? Thanks

EDIT:

Even doing this doesn't work??? Which If I echo: echo CAKE_CORE_INCLUDE_PATH; gives /Users/cameron/Sites/cake-1.3 and if I paste that in the address bar it loads up the cake folder so it's definitely the correct folder structure JUST it doesn't like looking at cake outside of the main url?

if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
    define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3'); echo CAKE_CORE_INCLUDE_PATH;
}

Upvotes: 4

Views: 7083

Answers (5)

Chuck Burgess
Chuck Burgess

Reputation: 11574

You are right on the money with:

define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');

Just make sure that Users sits in root. In other words, when you go to terminal you can get to this directory by typing: cd /Users/cameron/Sites/cake-1.3

It looks like you may be on a MAC. If so, your linking is correct. Most of the time what I find is you have done a copy paste of the app directory and it does not get the .htaccess files. I would check those first. But here is a comprehensive list of what you should verify:

  1. Make sure the host is pointing to the correct directory (/Users/cameron/Sites/sample-site/)
  2. Verify mod_rewrite is in fact on.
  3. Verify you have copied the .htaccess file in both the /Users/cameron/Sites/sample-site/ and the /Users/cameron/Sites/sample-site/webroot directories.
  4. Confirm that the /Users/cameron/Sites/cake-1.3/ directory has a directory called cake in it that contains the core.

Once all of this is confirmed, you will be good as gold!

Happy Coding!

UPDATE: When the index.php file looks for the cake core, it will look for a directory inside the location you are pointing to for another directory called cake. So in your case:

define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');

You must have the cake directory inside /Users/cameron/Sites/cake-1.3. Your directory structure will look like:

/Users/cameron/Sites/cake-1.3/cake
/Users/cameron/Sites/cake-1.3/cake/libs
/Users/cameron/Sites/cake-1.3/cake/config
/Users/cameron/Sites/cake-1.3/cake/console
etc.

CakePHP 3.0+ In CakePHP 3.0+ this configuration is moved out of webroot/index.php to App/Config/paths.php

Upvotes: 3

chronon
chronon

Reputation: 568

If you have access to your php.ini, you can add the path to Cake core there. Doing it this way means you don't have to change webroot/index.php at all. Example in php.ini:

include_path = ".:/usr/local/lib/php:/home/something/phpinc/cakephp2/lib"

According to the CakePHP 2.x docs, this is the recommended way to share the Cake core (assuming you have access to your php.ini).

Upvotes: 1

kaklon
kaklon

Reputation: 2432

There is no need to edit index.php.

Just put an alias (or link in UNIX) to your cake folder in each of your sites folder. Works perfectly. Same goes for plugins and vendors folder.

Upvotes: 0

Karl Andrew
Karl Andrew

Reputation: 1555

Is this a misunderstanding of the folder structure of CakePHP?

From the docs (CakePHP folder structure):

  • The app folder will be where you work your magic: it’s where your application’s files will be placed.
  • The cake folder is where we’ve worked our magic. Make a personal commitment not to edit files in this folder. We can’t help you if you’ve modified the core.

So the cake folder shouldn't change between all of your uses, therefore you have 1 copy. You can always change some of the functionality of the core by making your own changes in the app folder i.e. extending.

Upvotes: 0

Bil
Bil

Reputation: 543

You can have only one cake core but you must have one app folder (containing MVC) by site.

Upvotes: 0

Related Questions