Blue background with pattern

Manage your Magento shop via the command line - n98-magerun

Peter Jaap BlaakmeerOrange dotDec 22, 2022

4 min read

n98-what?

n98-magerun (ore 'magerun') is a command line (SSH) tool developed by Christian Münch of German netz98, among others. This tool was built to make managing and developing for Magento shops more pleasant by performing frequently occurring tasks via one-line SSH commands. A large number of less common but more difficult tasks can also be started via magerun.

Several command line tools have been developed for Magento, such as wiz or my own (buried) mate, for example. However, due to its many features, good build & code and ongoing development, Magerun has gained a large following within the Magento community and by now can be considered the de facto Magento command line tool.

Some functionalities for webshop administrators

Magerun's entire feature list can be found on their Github page, among others, but I will explain a few commonly used ones.

$ n98-magerun.phar cache:flush

This option allows you to quickly flush the entire cache. The entire Magento XML configuration is flushed, not just the files in var/cache.

$ n98-magerun.phar admin:user:create [username] [email] [password] [firstname] [lastname] [role]

Creates an admin user. Useful if you want to give automated access to multiple users.

$ n98-magerun.phar sys:cron:list

This option lists all cronjobs and when they are started. Normally you should open the cron_schedule folder in the database, but even then you only see the scheduled ticks and not when they are actually started. Indispensable feature to keep a good overview in your shop.

$ n98-magerun.phar sys:url:list --add-products 4

This option displays all product URLs in your shop. Useful for example to check crawlers or to send a bot for (Varnish/Redis) cache warming. The sys:url:list option also allows you to do this for categories and CMS pages. A few features for developers

$ n98-magerun.phar install

This feature allows you to quickly and easily set up a Magento installation. All required information will be asked to you during this process. First run n98-magerun.phar self-update to get the latest version so that the most recent Magento version is available.

$ n98-magerun.phar sys:setup:incremental

This function runs all setup scripts one by one. This gives you more transparency in the update process, especially useful for large-scale updates (e.g. from CE 1.6 to CE 1.8). If the update process goes wrong, you know exactly where.

$ n98-magerun.phar dev:template-hints [store_code] $ n98-magerun.phar dev:template-hints-blocks [store_code]

These functions allow you to enable and disable template (block) hints for different stores.

$ n98-magerun.phar dev:theme:duplicates theme [originalTheme]

Allows you to find duplicate files within your themes to detect cascading templates.

$ n98-magerun.phar dev:module:rewrite:conflicts

With this feature, magerun searches for conflicts within your Magento shop; extensions that override the same classes and/or blocks become easily and quickly visible.

There are many more options like creating a database dump, quickly putting down an extension skeleton, listening and installing extensions, opening a MySQL console, etc. Should you develop locally and work with the phpStorm IDE, you can use magerun from within your IDE. Check out the magerun.net site for more information on how to set this up.

extend n98-magerun with your own extensions

You can easily extend magerun itself with proprietary or third-party extensions in the form of Symfony2 commands. A great example is the 'Create dummy order' extension by Kalen Jordan that allows you to shoot a test order from the command line. How to do this yourself can be read here. Also, Magento guru Alan Storm has written a nice blog about this; Developing Commands for n98-magerun.

Meanwhile, in the develop branch in the Github repository is a version of magerun (written by Byte) that includes bash completion, so you can use the tab key to complete command names; a welcome addition given the sometimes long commands.

Adoption by Byte

Byte has made magerun available by default on their servers. If your shop is not running on a Byte server, check out the Github page or the magerun.net page on how to install magerun on your server (or move your shop to Byte ;-)).

This blog is intended to give a brief introduction to magerun. If you are interested in how the specific commands work, what they do and what you can do with them, check out Alan Storm's n98-magerun blog series.