The website you're upgrading must be on the latest CakePHP3. In your
composer.json
make sure you have
"cakephp/cakephp": "^3"
and run
php composer.phar upgrade
.
You will also need to have
a compatible phpunit installed:
php composer.phar require --dev phpunit/phpunit:"^5.7|^6.0"
Next, unlock your
composer.json
requirements:
"require": {
"cakephp/authentication": ">1.2",
"cakephp/cakephp": "^3",
"cakephp/migrations": ">3.0",
"cakephp/plugin-installer": ">1.0",
"friendsofcake/bootstrap-ui": ">1.0",
"friendsofcake/crud": ">5.0",
"friendsofcake/crud-view": ">0.14.0",
},
"require-dev": {
"cakephp/bake": ">1",
"cakephp/cakephp-codesniffer": ">3",
"cakephp/debug_kit": ">3",
},
This will let composer pick the right dependency versions as it upgrades without giving you numerous errors such as below.
Problem 1
- cakephp/authentication is locked to version 1.4.2 and an update of this package was not requested
Problem 2
- friendsofcake/bootstrap-ui is locked to version 1.4.3 and an update of this package was not requested.
- cakephp/migrations is locked to version dev-cake3 and an update of this package was not requested.
- Conclusion: don't install cakephp/cakephp 4.0.0 (conflict analysis result)
etc.
And here's how to actually upgrade.
cd /var/www
git clone git://github.com/cakephp/upgrade
cd /var/www/upgrade
git checkout master
php ../composer.phar install --no-dev
bin/cake upgrade file_rename locales /var/www/app3
bin/cake upgrade file_rename templates /var/www/app3
bin/cake upgrade rector --rules phpunit80 /var/www/app3/tests
bin/cake upgrade rector --rules cakephp40 /var/www/app3/src
cd /var/www/app3
php ../composer.phar require --dev --update-with-dependencies "phpunit/phpunit:^8.0"
php ../composer.phar require --update-with-dependencies "cakephp/cakephp:4.0.*"
php ../composer.phar require --dev cakephp/debug_kit:"^4.0"
You are likely to run into errors such as below:
PHP Deprecated: Use Cake\Error\ConsoleErrorHandler instead of Cake\Console\ConsoleErrorHandler. - /var/www/app3/vendor/composer/ClassLoader.php, line: 478
Deprecated: Use Cake\Error\ConsoleErrorHandler instead of Cake\Console\ConsoleErrorHandler. - /var/www/app3/vendor/composer/ClassLoader.php, line: 478
As well as…
The view for UsersController::login() was not found.
Template file `Users/login.php` could not be found.
The following paths were searched:
- `/var/www/app3/src/Template/Users/login.php`
- `/var/www/app3/vendor/cakephp/cakephp/templates/Users/login.php`
Update your
config/
files remaining from CakePHP3 using
their latest CakePHP4 counterparts.
PHP Fatal error: Declaration of App\Shell\ConsoleShell::getOptionParser() must be compatible with Cake\Console\Shell::getOptionParser(): Cake\Console\ConsoleOptionParser in /var/www/app3/src/Shell/ConsoleShell.php on line 25
An error message like the above actually guides you on what needs to be updated. If you need to see the full namespaced path of the class it wants, just search the
CakePHP CookBook.
A route matching "array ( 'prefix' => 'profile', 'controller' => 'settings', 'action' => 'index', 'plugin' => NULL, '_ext' => NULL, )" could not be found.
If using
$this->Html->link
, make sure your prefix and controller names start with an uppercase/capital letter.