Magento 2 root script is the quick method to print something, or get data, or check something with the use of Object manager.
For example, if you want to get the order details and print it, you can create root script in Magento 2.
Or, you may want to check the location of a Magento 2 store in the hosting which can be done using the root script, say, test.php.
Hence, creating a custom Magento 2 root script can be a time saver for a developer and the post shows the method for the same.
Steps to Create Root Script in Magento 2:
<?php use Magento\Framework\App\Bootstrap; require 'app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); echo 'Test Script';
That’s it.
Do share the solution with Magento Community via social media.
Thank you.