CakePHP Common core for multiple applications

In my local setup, I have a load of various CakePHP websites. I use a Mac, so the folder structure is similar to ~/Users/cameron/Sites/sample-website , and then on each of these sites I will have a typical Cake folder and App folder.

What I would like to do is to have only the main folder with cakes, and then ALL ALL sites to pull out from one core of the cake, so I do not have the same material several times. I read several guides online: http://rickguyer.com/cakephp-one-core-many-apps/

So, I have a folder for the cake 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 application folder and htaccess to tell where to find web road, etc.

Now I edited the index.php file inside webroot as a tutorial, but changed only one line because I did not move the OUTSIDE files from the application folder like it. So the only thing I changed is the following:

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

As far as I can tell, they look through two directories correctly and find a folder named cake-1.3 , but it just gives a 500 error?

Any ideas what the problem is? Thanks

EDIT:

Even that doesn't work ??? Which if I echo: echo CAKE_CORE_INCLUDE_PATH; gives /Users/cameron/Sites/cake-1.3 , and if I paste it into the address bar, it loads the cake folder, so that definitely the correct JUST folder structure doesn’t like to look at the cake outside 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; } 
+4
source share
5 answers

You are right for the money:

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

Just make sure users are seated at the root. In other words, when you go to the terminal, you can get into this directory by typing: cd /Users/cameron/Sites/cake-1.3

Sounds like you might be on a MAC. If so, your link is correct. In most cases, I find that you made a copy in the application directory and it does not receive .htaccess files. I would check them first. But here is a complete list of what you should check:

  • Make sure the host points to the correct directory ( /Users/cameron/Sites/sample-site/ )
  • Check if mod_rewrite is really enabled.
  • Make sure you copy the .htaccess file to both /Users/cameron/Sites/sample-site/ and /Users/cameron/Sites/sample-site/webroot directories.
  • Confirm that the /Users/cameron/Sites/cake-1.3/ directory has a directory called a cake in it that contains the kernel.

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

Happy coding!

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

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

You should have a cake directory inside /Users/cameron/Sites/cake-1.3 . Your directory structure will look like this:

 /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 migrated from webroot / index.php to App / Config / paths.php

+3
source

If you have access to your php.ini, you can add the path to the Cake core there. Doing this means that you don’t need to change webroot / index.php at all. An example in php.ini:

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

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

+1
source

You can only have one core for the cake, but you must have one application folder (containing MVC) per site.

0
source

Is this a misunderstanding of the CakePHP folder structure?

From the docs ( CakePHP folder structure ):

  • Your magic will work in the application folder: where your application files will be placed.
  • While we were working on our magic, we used a cake. Make a personal commitment not to edit the files in this folder. We cannot help you if you changed the kernel.

Therefore, the cake folder should not change between all your needs, so you have 1 copy. You can always change some kernel functions by making your own changes to the app folder, i.e. expanding.

0
source

No need to edit index.php.

Just put an alias (or link on UNIX) in your cake folder in every folder on your site. Works great. The same goes for the plugins and vendors folder.

0
source

All Articles