{"id":1455,"date":"2020-12-11T14:58:00","date_gmt":"2020-12-11T14:58:00","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/create-root-script-in-magento-2\/"},"modified":"2025-05-22T11:21:05","modified_gmt":"2025-05-22T05:51:05","slug":"create-root-script-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/create-root-script-in-magento-2\/","title":{"rendered":"How to Create Root Script in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 root script is the quick method to print something, or get data, or check something with the use of Object manager.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, if you want to get the order details and print it, you can&nbsp;<em><strong>create root script in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Create Root Script in Magento 2:<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\n\nuse Magento\\Framework\\App\\Bootstrap;\nrequire 'app\/bootstrap.php';\n$bootstrap = Bootstrap::create(BP, $_SERVER);\n$objectManager = $bootstrap->getObjectManager();\n$state = $objectManager->get('Magento\\Framework\\App\\State');\n$state->setAreaCode('frontend');\necho 'Test Script';<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do share the solution with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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,&#8230;<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1455","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1455"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1455\/revisions"}],"predecessor-version":[{"id":14580,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1455\/revisions\/14580"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}