In Magento 1 I can use

require_once '../app/Mage.php';
$products = Mage::getModel('catalog/product')->getCollection();

Where is the new "/app/Mage.php" in Magento 2? What file I have to include in my external PHP file?


1 Answer 1


Call of Application:

Try this

In magento2 There no app.php

It have bootstrap.php which is main hero magento 2.

    use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManager;

require YoutmagetoDir. '/app/bootstrap.php';
 /* set Parameters for application */

$opt['group'] = 'default';
$opt['standaloneProcessStarted'] = '0';
$params = $_SERVER;
/* you can out your store id here */
$params[StoreManager::PARAM_RUN_CODE] = 'admin';
$params[Store::CUSTOM_ENTRY_POINT_PARAM] = true;

/* create application */
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/* the applocation 
/** @var \Magento\Framework\App\Cron $app */

$app = $bootstrap->createApplication('Magento\Framework\App\Cron', ['parameters' => $opt]);
  • createApplication() initialize magento application

    On above example function we have send the store code(PARAM_RUN_CODE) as admin.

  • run() function is execute the application

Not the answer you're looking for? Browse other questions tagged or ask your own question.