How to Install and Use n98-magerun2 to Manage Magento 2 Websites
Chirag DodiaDecember 17, 2020
Magento 2 default provides a command-line interface to perform some basic operations like installation, modules enable/disable, admin user creation, cache cleaning, etc.
However, as a Magento 2 developer, you have to perform some additional operations during development like dumping database for development, running cron locally, creating dummy customers, etc. There is no such command available in default CLI to perform these jobs.
n98-magerun2 is a command-line tool that provides some handy commands to manage your Magento 2 websites. With the help of commands, you can perform some important operations in Magento 2 without login to your admin panel.
In this tutorial, we will see how to install n98-magerun2 and an overview of some important commands and its use.
How to Install n98-magerun2
- Step 1: Download the latest version using wget command
- Step 2: Make the phar file executable
chmod +x ./n98-magerun2.phar
- Step 3: Copy phar file to /usr/local/bin to use the command system wide
sudo cp ./n98-magerun2.phar /usr/local/bin/
- Step 4: Verify installation
If it is installed successfully then the above command will show the output like this
n98-magerun2 version 3.2.0 by netz98 GmbH
Basic n98-magerun2 Commands
We will see some basic command which can be useful in day to day Magento 2 development.
This command will display all the important information about your Magento 2 installation like Magento 2 version, edition, Attributes, Products, Categories, Customers, etc.
Many times while developing, you need to create dummy customers by filling forms either from the frontend or from the admin panel. Using this command, you can quickly create the customer from the terminal.
N98-MAGERUN2.PHAR SYS:CRON:RUN MY_JOB_CODE
Using this command you can easily run a cron job in your local system while developing as well as in server.
N98-MAGERUN.PHAR DB:DUMP –COMPRESSION=”GZ” FILENAME
Using this command you can simply dump the Magento database. Sometimes for local development or for staging sites, you do not need all tables. Using this command you can also exclude some tables.
N98-MAGERUN2.PHAR DB:DUMP –STRIP=”@STRIPPED”
The above command will strip logs and sessions from the database. There are many strip options available you can check in this https://github.com/netz98/n98-magerun2#stripped-database-dump link.
Apart from these commands, there are many commands available in n98-magerun2. You can check all available command by running the below command:
N98-magerun2 is a really helpful tool for Magento 2 developers. As a Magento 2 developer, you can perform many operations using this tool which is not possible in default Magento 2 CLI.
If you haven’t already tried n98-magerun2, give it a try today.
Author Bio: Chirag Dodia
Chirag Dodia: 2x Magento 2 Certified developer. Apart from Magento, Dodia has intermediate knowledge of Codeignitor CMS and WordPress Blog Platform. In his free time, he reads blog posts on the internet and writes his own blog at htttps://www.codextblog.com.
Let's build something together!
Contact us today to get your project started and hear more about all the awesome things we can do for you!
Become the Next Success Story