Home » Magento, Magento 215 August 2016

Magento 2: Run code in external file/script

This article shows how to run Magento 2 code in an external file/script. The external file can be inside the Magento root folder or outside of it.

This example considers that the file is present in the Magento 2 root folder. Let us name the file as abc.php. So, we want to execute some code when we open http://example.com/abc.php.

Here is the code to be written in the external file.

A good discussion is going on here regarding this topic.

Hope this helps. Thanks.

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • magento

  • Vivek Shingala

    Hi Mukesh

    Thanks for your post.

    When I use this code, in Magento 2.1.8, I get following error. Could you please let me know the way to fix it please?

    TypeError: Argument 2 passed to MagentoFrameworkAppHttp::__construct() must be an instance of MagentoFrameworkEventManager, none given, called in C:xampphtdocsmagento2vendormagentoframeworkObjectManagerFactoryAbstractFactory.php on line 93 in C:xampphtdocsmagento2vendormagentoframeworkAppHttp.php on line 85