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';
@hackzilla
Copy link

add the autoload to the top of the bootstrap file.

@kAlvaro
Copy link

kAlvaro commented Aug 20, 2018

In recent Composer releases you apparently need "https://github.com/cakephp/cakephp.git" as package URL so it uses HTTPS:

[Composer\Downloader\TransportException]
Your configuration does not allow connections to git://github.com/cakephp/cakephp.git. See https://getcomposer.org/doc/06-config.md#secure-http for details.

Fixed that, it works flawlessly.

@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