Run external script from magento 2 directory [Magento 2]

<?php
use Magento\Framework\App\Bootstrap;

require __DIR__ . '/app/bootstrap.php';

//$rootDirectoryPath = '/var/www/html/magento2';
//require $rootDirectoryPath . '/app/bootstrap.php';

$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$orderId = 51;
$order = $obj->get('Magento\Sales\Model\Order')->load($orderId);

echo '<pre>';
print_r($order->getOrigData());
echo '</pre>';
?>

Comments