As the oficial n98-magerun repo on GitHub says:

The swiss army knife for Magento developers, sysadmins and devops. The tool provides a huge set of well tested command line commands which save hours of work time. All commands are extendable by a module API.

Magerun is the tool for Magento development. In this article we will talk you through some of the most useful commands.

The following tutorial shows how to install n98-magerun CLI in phpstorm ide.


 


So what it can do for me?

I would answer this like so -- it will make your life simpler by using some nifty commands that we do use everyday. Check this out!

Tip: It is handy to keep a terminal window open all time when working with Magento.

Cache

Many problems in Magento can be solved by clearing cache. To do so, you usually have to log in to Magento panel and go to System > Cache Management > Flush Magento Cache. However, that’s simply too much clicking for a savvy Magento dev. What can you do instead?

$ n98-magerun.phar cache:flush

(Re-)index

The problems that can’t be solved by clearing cache can be often fixed with re-indexing. „Did you try clearing cache and reindexing?” is the new „Did you try turning it off and on again?”. Don’t fancy clicking through the panel? There you go:

$ n98-magerun.phar index:reindex:all

Cron

Sooner or later every Magento developer has to deal with cron jobs. Sooner or later something isn’t going to work. What then? Modify the code, wait for the next scheduled run and check the results? Certainly not. First remember to check if the job is executed at all:

$ n98-magerun.phar sys:cron:history

Then, run it manually:

$ n98-magerun.phar sys:cron:run

Modify it and run it again. And again. And possibly again… Until it works.

 

Admin Usage

Your client has given you a database dump without the password to the panel? You need to access the panel, but your client doesn’t want you to fiddle with the production site? Not sure what to do?
Either:

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

or:

$ n98-magerun.phar admin:user:change-password [username] [password]

This will give you a full access to the panel on your server and your client won’t be concerned about their shop.

 

Database Usage

When working simultaneously on a development server, client server, locally and possibly on few other installations, you’ll need to dump the database in one place and upload it to a different one. We mostly like to use phpMyAdmin and have to ensure that upload_max_filesize, and max_execution_time is set in php.ini file. And then hope that server will not timeout till the file is ready to be downloaded. But with n98-magerun, it goes as smooth as below.

$ n98-magerun.phar db:dump [filename]

and

$ n98-magerun.phar db:import [filename]

become your best mates. Also, you usually don’t need sales and customer data when launching a development copy of your client’s shop. Moreover, you don’t want to have customer data on your server because if something goes wrong, you’re in big big trouble. A simple solution gives:

$ n98-magerun.phar db:dump -s @development [filename]

If you use version control, you’ll most likely find this command useful:

$ n98-magerun.phar db:dump –human-readable -s @development [filename]

List modules

You often have to investigate which modules (and which versions) are installed in a particular Magento instance. You can look through the files or check it in the panel (System > Configuration > Advanced > Disable Modules Output). But there’s also an easier and quicker way to do it:

$ n98-magerun.phar sys:modules:list

This command will give you a table containing codepool, full name, version and the status of all extensions.

For all available command please visit this page.

Cheers!

Categorized in: