0

Hi I have a php script that starts like this:

<?php

require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();

How do I call app/Mage.php from a directory other than root?? i.e I have my script in public_html/shell but app is in public_html/

1

In normal case you can call it like:

<?php
require_once('../app/Mage.php'); // "../" represent the parent directory
umask(0);
Mage::app();

If you are running the script via a cron job, use below to make sure that the cron is in the correct directory:

<?php
chdir(dirname(__FILE__));
require_once '../app/Mage.php';
umask(0);
Mage::app();
1

Try this:

require_once('../app/Mage.php');
0

You dont need to write this thigs if your script in shell folder

You can create shell script and also you can use it from browser and CLI as well . below file name is test.php in shell folder

 <?php
    //ini_set('display_errors', 1); 
    require_once 'abstract.php';
    class Mage_Shell_Test extends Mage_Shell_Abstract{

        public function run(){
            Mage::app();
           //you can do whatever you want to do in this method

        }

        public function _validate() {
           // this function allows you to use this script from browser  
             return true;
        }



    }

    $shell = new Mage_Shell_Test();
    $shell->run();

    ?>
0

If your script is required to be outside Magento folder then just use chdir() as first line.

In your case:

<?php

chdir('/var/www/fullpath_where_index_php_is');
require_once('app/Mage.php');

umask(0);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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