Resolve Magento 1 / Magento 2 root folder running inside the Magento tree but w/o Magento env, php module (include)

PHOTO EMBED

Sat Jan 08 2022 05:57:18 GMT+0000 (UTC)

Saved by @juliyvchirkov #php #magento #document_root #resolve #module #include

<?php

$mageRoot = __DIR__;

while (!(file_exists($mageRoot . '/app/Mage.php') || file_exists($mageRoot . '/bin/magento'))) {
    $mageRoot = dirname($mageRoot);
}

return $mageRoot;
content_copyCOPY

https://gist.github.com/juliyvchirkov/2c5c8d54b182528e39d4565d1632f8ee#file-magentodocumentroot-php