Running custom shell commands in Magento

If you need to export some data from magento or to change them the best thing is to create a custom shell command. To do that please follow these steps:

  1. Go to shell folder and create a new file test.php
  2. Open the file that you created and insert this code:
    require_once 'abstract.php';
    require_once '../app/Mage.php';
    class Test extends Mage_Shell_Abstract
        public function run()
            if ('actionName' == $this->getArg('action')) {
                echo "Code Here"; exit();
                echo $this->usageHelp();
        public function usageHelp()
            return <<<USAGE
    Usage:  php -f importer.php -- [options]
      --action actionName     
      Or any text you like
    $shell = new Test();
  3. You can run this script by:
    php -f test.php -- action actionName

Getting 500 internal server error – Magento images

Let’s suppose that you copied a magento project to your local server and the images are missing.

Here are some things that you should check it:

  • See what owner is assigned to the media folder. To do that you have to execute the following linux command in your console:
ls -l

To change recursively the ownership of the media folder you have to execute this command:

chown -R username:group media

Do not execute chown -R username:group / 

    • Another issue that  might cause this, is the media folder permissions. You should execute this command:
      chmod -R 777 media/
  • If not of these are working you should check afther a .htaccess file inside the media folder and remove it!
  • Don’t forget to clear the cache from admin panel and also clear the cache from your browser (ctrl+shift+delete).