This is a weird request but I've done it before and it worked wonders.

I have a need to make a custom PHP file in my sites root folder. I need to give this file access to all of the magento functions inside.

$setup = new Mage_Eav_Model_Entity_Setup(‘core_setup’);

I did this once before successfully when I wrote a script to parse a massive database of trading cards into useful data then has the php script automatically add the cards to the database.

My problem is I did this on a old version of XMAPP that I sadly lost the backup files of when my pc died.

What files do I need to include in a blank php file to have access to the required magento core functions?

2 Answers 2


Try this

require 'app/Mage.php';

Now Magento is all fired upp and ready to go

  • Thanks, now I can finally play with my Module install script without having to delete the messed up versions 20 times an hour :) Sep 18, 2013 at 8:49
  • 3
    Setting the store is not mandatory. Sep 18, 2013 at 9:04
  • 1
    AFAIK, It's mandatory in case if you want some write operation to the database.
    – MagePsycho
    Sep 18, 2013 at 13:39
  • 1
    @MagePsycho Only mandatory for updates to the product and category entities.
    – benmarks
    Feb 6, 2014 at 21:56
  • @ChrisMorris this script will not trigger the update workflow. You will want to call Mage_Core_Model_Resource_Setup::applyAllUpdates()
    – benmarks
    Feb 6, 2014 at 21:56

I use this one in my /cron/ folder:


error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
setlocale(LC_TIME, 'en_US');

$compilerConfig = 'includes/config.php';
if (file_exists($compilerConfig)) {

$mageFilename = dirname(__FILE__) . '/../app/Mage.php';

require_once $mageFilename;



// If you're going to use store view emulation:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.