Multiple CakePHP applications on a single domain in a shared LAMP hosting environment

GOAL:

BACKGROUND:

I first worked out this process on a WAMP machine, and I may cover that in another article.   But since the actual end game is for my public space on the web (shared LAMP / CPanel hosting), I am going to cover this first.   Specifically I use WAMP for development and testing, LAMP for publishing.

My LAMP hosting is with NetworkRedux.com.   They have mod_rewrite already installed.   NO FURTHER modifications to the hosting environment were made by me other than what is outlined here, the basis for which is already in the Cake PHP manual.

As you go through this and build your application, notice that the models, controllers, and views folders are all in the cakeApp1 folder in the private server space above the public webspace.

ACTION ITEMS:

TEN STEPS TO DEPLOYING YOUR FIRST APPLICATION (cakeApp1)

  1. Download the current CakePHP distribution.
  2. Unpack
  3. For this example, we will be creating an application called cakeApp1.

  4. Create three folders to split up the files from the distribution.
  5. From the distribution, copy cake and vendors folders into your new cake folder.
  6. From the distribution, copy the app folder into the private cakeApp1 folder
  7. From within the cakeApp1/app folder in the previous step, select the CONTENTS of the webroot folder and move them to the public cakeApp1 folder
  8. Your folders should look like this:
    (private - above the public webspace)
    /cake
    	/cake
    		/app_controller.php
    		/app_model.php
    		/basics.php
    		/bootstrap.php
    		/config
    		/dispatcher.php
    		/docs
    		/libs
    		/scripts
    	/vendors
    /cakeApp1
    	/config
    	/controllers
    	/index.php
    	/models
    	/plugins
    	/tmp
    	/vendors
    	/views
    
    (public - within the public webspace)
    /cakeApp1
    	/.htaccess
    	/css
    	/css.php
    	/favicon.ico
    	/files
    	/img
    	/index.php (*edit this in the next step*)
    	/js
    	/
    
  9. Open (from the public side) /cakeApp1/index.php
  10. Edit /cakeApp1/index.php (partial, comments removed)
  11. (This is the arrangement on my hosting account, yours may differ)
    	if (!defined('ROOT')) {
    		 define('ROOT', DS.'home'.DS.'username'.DS.'cakeApp1');
    	}
    	if (!defined('APP_DIR')) {
    		 define('APP_DIR',dirname('cakeApp1'));
    	}
    	if (!defined('CAKE_CORE_INCLUDE_PATH')) {
     		 define('CAKE_CORE_INCLUDE_PATH', DS.'home'.DS.'username'.DS.'cake');
    	}
    
  12. Open (from the private side) /cakeApp1/config/database.php.default (or database.php if you have previously setup your database config)
  13. Edit class DATABASE_CONFIG with your connection info for the current application.

This last step is what points THIS app to a particular database.   When you setup the next app, the info here can point it to a separate database on the same server - different apps / different source folders / different databases / one hosting account on a shared public server

Don't forget that the models, controllers, and views folders are all in the cakeApp1 folder in the private server space above the public webspace.

FOUR STEPS TO DEPLOYING A SECOND APPLICATION (cakeApp2):

  1. Put above the public webspace (private):
  2. /cakeApp2
    	/config
    	/controllers
    	/index.php
    	/models
    	/plugins
    	/tmp
    	/vendors
    	/views
    
  3. Put within the public webspace (public):
  4. /cakeApp2
    	/.htaccess
    	/css
    	/css.php
    	/favicon.ico
    	/files
    	/img
    	/index.php 
    	/js
    	/
    
  5. Edit /cakeApp2/index.php in the public webspace to have the correct server paths as you did in cakeApp1 above (step 8).
  6. Edit /cakeApp2/config/database.php (from the private side) to contain your database connection information.

Enjoy your cake!

Jeff Keith

aka Dunnottar