Skip to content

Instantly share code, notes, and snippets.

@matheuseduardo
Forked from ogrrd/Cake Composer.md
Created July 9, 2018 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matheuseduardo/57260e4a428dc2a1e79c4ada3c223f3b to your computer and use it in GitHub Desktop.
Save matheuseduardo/57260e4a428dc2a1e79c4ada3c223f3b 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';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment