Life saver - live dev on Magento Cloud

Not many know about this but we can do live development / debugging on Magento. I will share quickly how to do that below. Thanks to James Cowie and Sylvain Delbosc for helping me get good sleep even with blocker issues coming :D.

Once we login to Magento cloud, we get all our code in /app directory and all the code is made readonly. This makes it difficult to edit any file and add logs or change code to verify our code changes on dev server. This is really required with complex architectures where we have integrated systems and issues are with specific scenarios which are not possible to replicate in local machines.

Most of the code is in Classes and glad we are using auto loaders :). There is a scope of adding our classes in /app/app/etc/NonComposerComponentRegistration.php file before all the code to include all files (basically right after the file comment). This will ensure our classes are loaded and not the ones from actual modules.

To do this, we have to copy our files inside /app/var dir which is writeable. For instance if we want to modify anything in vendor/magento/module-customer/Model/Customer.php we just need to copy it to var

mkdir -p /app/var/vendor/magento/module-customer/Model
 
cp /app/vendor/magento/module-customer/Model/Customer.php /app/var/vendor/magento/module-customer/Model/Customer.php

and add it to /app/app/etc/NonComposerComponentRegistration.php like below.
 
<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
 
require_once('/app/var/vendor/magento/module-customer/Model/Customer.php');
 
$pathList[] = dirname(__DIR__) . '/code/*/*/cli_commands.php';

And that's it, now whatever you change in your file inside var will be executed.

Beware, this will be reverted back on next deployment. But we only want it to be temporary change for debugging or verifying code change so should be good.

PS - we can also enable XDEBUG if there is bigger issue to debug, there is good documentation available here.
 

Add new comment

9 + 10 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.