Migrating from Cakephp 2 to Cakephp 3 one module at once




Is it possible to have an application written in CakePhp version 2.5 and a new version using CakePhp
3 coexisting ? and sharing the authentication session ?

Just to try to migrating one module at once from version 2 to version 3 from an huge CakePHP aplication.

Can the two versions coexists for one single application ?

Anyone already tried and have some issues using this aproach ?

Share Database Sessions between cakephp 2 and cakephp 3

I’m doing a migration from 2 to 3 on an apache server at the moment. So far I have managed to make them coexist using a virtualhost with the root directory one level above both application directories, so that the structure is

  • /rootdir/
    • cakephp2site/
      • app/
        • webroot/
    • cakephp3site/
      • webroot/

Then, using a .htaccess file within rootdir, I have

RewriteEngine on RewriteRule ^users(.*)$ cakephp3site/webroot/$1 [L] RewriteRule ^$ cakephp2site/app/webroot/ [L] RewriteRule (.*) cakephp2site/app/webroot/$1 [L]

To explain, my users controller is cakephp 3 ready, so anything with /users can be routes to the cakephp 3 application. Everything else goes to the cakephp 2 application until I’ve done the changes.

As for auth, if running on the same instance, the php cookie name is PHPSESSID for cakephp 2 and CAKEPHP by default in cakephp 3, but this can be renamed at the bottom of app.php with

'Session' => [
    'defaults' => 'php',
	'cookie' => 'PHPSESSID' //<-- add this line