🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Create Root Script in Magento 2

By Jignesh ParmarUpdated on May 22, 2025 1 min read

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.

Jignesh Parmar Full Image
Article byJignesh Parmar

An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.