Skip to content

Instantly share code, notes, and snippets.

@ogrrd
Last active July 15, 2024 22:03
Show Gist options
  • Save ogrrd/5961303 to your computer and use it in GitHub Desktop.
Save ogrrd/5961303 to your computer and use it in GitHub Desktop.
Install Cake 2.x with Composer

Install CakePHP 2.x with Composer

Remove the main CakePHP lib directory

$ cd /path/to/your/website
$ rm -Rf ./lib

Add the following composer.json file

Put it in the top level, NOT in app/!

{
  "minimum-stability": "dev",
  "config": {
      "vendor-dir": "vendors"
  },
  "repositories" : [
    {
      "type": "package",
      "package": {
        "name" : "cakephp/cakephp",
        "version" : "2.4.1",
        "source" : {
          "type" : "git",
          "url" : "git://github.com/cakephp/cakephp.git",
          "reference" : "2.4.1"
        },
        "bin" : ["lib/Cake/Console/cake"]
      }
    }
  ],
  "extra": {
    "installer-paths": {
      "app/Plugin/DebugKit": ["cakephp/debug_kit"]
    }
  },
  "require" : {
    "php": ">=5.3",
    "cakephp/cakephp" : "2.4.*",
    "cakephp/debug_kit": "2.2.*"
  }
}

Install defined composer stuff

$ composer update

Create a project (if you don't already have one)

$ vendors/bin/cake bake project $(pwd)/app

Tell CakePHP where to find the new library

Update app/webroot/index.php and app/webroot/test.php

Replace this...

<?php
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');

...with this

<?php
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'vendors' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib');

Update app/Console/cake.php

Replace this...

<?php
$root = dirname(dirname(dirname(__FILE__)));

...with this

<?php
$root = dirname(dirname(dirname(__FILE__))) . $ds . 'vendors' . $ds . 'cakephp' . $ds . 'cakephp';

Use composer autoloader

Add this to the top of app/Config/bootstrap.php

<?php
require dirname(dirname(__DIR__)) . '/vendors/autoload.php';
@Raunter
Copy link

Raunter commented Aug 29, 2018

Update the config section ...

"config": {
"vendor-dir": "vendors",
"secure-http":false
}

@EOM
Copy link

EOM commented May 9, 2020

Hi min fix is: DS

$root = dirname(dirname(dirname(__FILE__))) . DS . 'vendors' . DS . 'cakephp' . DS . 'cakephp';

And End use
composer dumpautoload -o

Ahh Add attach + info for composer and CakePHP 2.x :
https://onoya.dev/install-cakephp-2-using-composer/
Using Namespaced:
https://blog.garr.co.uk/php/2015/10/01/using-namespaced-classes-in-cakephp2.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment