Knowledge Base

How to manage Magento Connect extensions from the command line

This article describes how to use the mage script to manage Magento Connect extensions from the command line.

The information in this article only applies to Magento 1.9 and older versions. Magento 2 does not have the mage script.

About the mage script

Magento includes the mage script to help you manage Magento Connect extensions. Because it is a command-line application, the mage script can be used in cron jobs and other automation tools.

Unfortunately, older versions of Magento do not have a complete command-line interface administration solution like WP-CLI for WordPress or Drush for Drupal. Magento 2, however, does have a complete command-line interface; for more information, please see this article.

Configuring the mage script

The mage script is included with Magento by default, but it is not configured to run. To configure the mage script, follow these steps:

  1. Log in to your account using SSH.
  2. At the command prompt, type the following commands:
    cd ~/public_html
    chmod 700 mage
    If you installed Magento in a subdirectory beneath the public_html directory, change to that directory instead before running the chmod command.
  3. To see a list of available commands for the mage script, type the following command:

    ./mage

Listing extensions

To view the extensions currently installed for your Magento site, type the following command:

./mage list-installed

To view a list of all of the extensions available in the default community channel, type the following command:

./mage list-available

This command generates a very long list. To filter the results, you can use the grep command. For example, to list all Magento extensions related to search, type the following command:

./mage list-available | grep -i search

Most, if not all, of the extensions you manage are in the default community channel. However, if you need to work with extensions from a third-party channel, you can use the channel-add option to add a channel. Type the following command, replacing channel with the URL of the channel you want to add:

./mage channel-add channel

The commands in this article assume that you are using the community channel.

Downloading and installing extensions

To download and install an extension in one step, type the following command, replacing name with the name of the extension you want to install:

./mage install community name

To download an extension without installing it, type the following command, replacing name with the name of the extension you want to download:

./mage download community name

To install an extension you have already downloaded, type the following command, replacing filename with the path and name of the file that you want to install:

./mage install-file filename

Upgrading extensions

To determine if there are any upgrades available for your installed extensions, type the following command:

./mage list-upgrades

You can upgrade a specific extension, or you can upgrade all extensions at once. To upgrade all extensions at once, type the following comand:

./mage upgrade-all

To upgrade a specific extension, type the following command, replacing name with the name of the extension that you want to upgrade:

./mage upgrade community name

Uninstalling extensions

To uninstall an extension, type the following command, replacing name with the name of the extension you want to remove:

./mage uninstall community name

Using cron to automate extension management

You can easily use the mage script in cron jobs to automate administration tasks for your extensions. For example, the following cron configuration upgrades all extensions every Sunday at 2:00 AM:

0 2 * * Sun cd /home/username/public_html && ./mage upgrade-all

For more information about how to run PHP scripts from cron jobs, please see this article.