Magento 2: n98-magerun2 Tool
n98-magerun2 is a powerful command-line tool that extends Magento 2’s native CLI (bin/magento) with many developer-friendly commands to speed up development, debugging, and administration.
Table of Contents
Overview
What is n98-magerun2.phar?
n98-magerun2 is:
A powerful command-line tool that extends Magento 2’s native CLI (bin/magento) with many developer-friendly commands to speed up development, debugging, and administration
The Magento 2 version of the popular n98-magerun for Magento 1
The n98 magerun CLI Tools provides some handy tools to work with Magento / Mage-OS / Adobe Commerce from command line
Source & Documentation
Atwix: https://www.atwix.com/magento-2/n98-magerun2-tool-overview/
Built-in Docs: Use
n98-magerun2.phar listandn98-magerun2.phar help <command>for built-in help
Installation
Follow these steps to install n98-magerun2:
Download n98-magerun2 using one of the following methods:
Using wget:
wget https://files.magerun.net/n98-magerun2.phar
Using curl:
curl -O https://files.magerun.net/n98-magerun2.phar
Make the downloaded file executable:
chmod +x n98-magerun2.phar
Move it to
/usr/local/bin(recommended):This allows you to run n98-magerun2.phar from any location:
sudo mv n98-magerun2.phar /usr/local/bin/mage2run
Verify the installation:
mage2run --version
Create Alias (Optional)
If you prefer not to create the global alias, you can create a shell alias instead.
Note
If you created the global alias above (/usr/local/bin/mage2run), you can skip this section. This is only if you want a different alias name.
Open the shell configuration file:
code ~/.bashrc
Add the following line at the end of the file:
alias n98mage='/usr/local/bin/n98-magerun2.phar'
Save the file and exit the editor
Apply the changes to the current shell session:
source ~/.bashrc
Test the alias:
n98mage list
Available Commands
n98-magerun2 provides all the default Magento commands from bin/magento plus additional commands listed below.
Core Commands
Command |
Description |
|---|---|
|
Internal command to provide shell completion suggestions |
|
Install Magento |
|
Open the current project in the browser |
|
Runs multiple n98-magerun commands |
|
Updates n98-magerun2.phar to the latest or a specified version |
Admin Commands
Command |
Description |
|---|---|
|
Toggles admin notifications |
|
Create a new token for an admin user |
|
Changes the password of an adminhtml user |
|
Set/toggle the status of an admin user |
|
Delete the account of an adminhtml user |
|
List admin users |
Cache Commands
Command |
Description |
|---|---|
|
Flush catalog image cache |
|
Lists all magento caches |
|
Remove cache entry by id |
|
Prints a cache entry |
CMS Commands
Command |
Description |
|---|---|
|
Toggle Cms Block status |
Configuration Commands
Command |
Description |
|---|---|
|
Prints acl.xml data as a table |
|
Dump dependency injection config |
|
Dump the merged data of indexer.xml files |
|
Dump merged data of mview.xml files |
|
Create an env file interactively |
|
Delete the entry from env.php |
|
Set value in env.php |
|
List env.php file |
|
Search system configuration descriptions |
|
Deletes a store config item |
|
Get a store config item |
|
Set a store config item |
Customer Commands
Command |
Description |
|---|---|
|
Adds an address to a customer |
|
Changes the password of a customer |
|
Creates a new customer/user for the shop frontend |
|
Deletes a customer/user by matching or fuzzy search and/or range |
|
Loads basic customer info by email address |
|
Lists all magento customers |
|
Create a new token for a customer |
Database Commands
Command |
Description |
|---|---|
|
Add default entry to authorization_role and authorization_rule tables |
|
Opens mysql client by database config from env.php |
|
Create currently configured database |
|
Drop current database |
|
Dumps database with mysqldump cli client |
|
Imports database with mysql cli client according to database defined in env.php |
|
Dumps database informations |
|
Check database tables |
|
Executes an SQL query on the database defined in env.php |
|
Shows important server status information or custom selected status values |
|
Shows important variables or custom selected |
Design Commands
Command |
Description |
|---|---|
|
Toggles demo store notice for a store view |
Development Commands
Command |
Description |
|---|---|
|
Clear static assets |
|
Opens PHP interactive shell with a initialized Magento application |
|
Decrypt the given value using magento’s crypt key |
|
Lists all registered preferences |
|
Encrypt the given value using magento’s crypt key |
|
Create and register a new magento module |
|
Search for soft and hard dependencies for Magento 2 modules |
|
List all installed modules |
|
Lists all registered observers |
|
Get count of report files |
|
Toggle allow symlinks setting |
|
Toggles template hints |
|
Toggles template hints block names |
|
Build Hyvä theme CSS |
|
Lists all available themes |
|
Toggle the inline translation tool for the admin |
|
Export inline translations |
|
Adds a translation to the core_translate table globally for locale |
|
Toggle the inline translation tool for the shop |
EAV Commands
Command |
Description |
|---|---|
|
List EAV attributes |
|
Remove attribute for a given attribute code |
|
View information about an EAV attribute |
Generation Commands
Command |
Description |
|---|---|
|
Flushes generated code like factories and proxies |
GitHub Commands
Command |
Description |
|---|---|
|
Download patch from github merge request (experimental) |
Index Commands
Command |
Description |
|---|---|
|
Lists all magento indexes |
|
ReCreate all triggers |
Integration Commands
Command |
Description |
|---|---|
|
Create a new integration |
|
Delete an existing integration |
|
List all existing integrations |
|
Show details of an existing integration |
Media Commands
Command |
Description |
|---|---|
|
Creates an archive with content of media folder |
Route Commands
Command |
Description |
|---|---|
|
Lists all registered routes |
Sales Commands
Command |
Description |
|---|---|
|
Add the sequence tables and metadata for given store or all stores |
|
Remove sequence tables and metadata for given store or all stores |
Script Commands
Command |
Description |
|---|---|
|
Lists all scripts in repository |
|
Run script from repository |
Search Commands
Command |
Description |
|---|---|
|
Lists all registered search engines |
System Commands
Command |
Description |
|---|---|
|
Checks Magento System |
|
Last executed cronjobs with status |
|
Kill cron jobs by code |
|
Lists all cronjobs |
|
Runs a cronjob by job code |
|
Schedule a cronjob for execution right now, by job code |
|
Prints info about the current magento system |
|
Toggles maintenance mode if –on or –off preferences are not set |
|
Change module resource version |
|
Compare the module version with the setup_module table |
|
Automatically downgrade schema and module versions |
|
Lists all base urls |
|
Lists all installed store-views |
|
Get all urls |
|
Lists all websites |
Common Usage Examples
Here are some commonly used commands and examples:
Admin User Management
List all admin users:
mage2run admin:user:list
Create admin token:
mage2run admin:token:create admin_username
Change admin password:
mage2run admin:user:change-password admin_username
Database Operations
Open MySQL console:
mage2run db:console
Dump database:
mage2run db:dump filename.sql
Import database:
mage2run db:import filename.sql
Execute SQL query:
mage2run db:query "SELECT * FROM admin_user"
Cache Management
List all caches:
mage2run cache:list
Flush image cache:
mage2run cache:catalog:image:flush
Configuration
Show env.php contents:
mage2run config:env:show
Set configuration value:
mage2run config:store:set web/unsecure/base_url http://example.com/
Get configuration value:
mage2run config:store:get web/unsecure/base_url
Customer Management
List all customers:
mage2run customer:list
Get customer info:
mage2run customer:info customer@example.com
Create customer token:
mage2run customer:token:create customer@example.com
Development Tools
List all modules:
mage2run dev:module:list
List observers:
mage2run dev:module:observer:list
Open PHP console:
mage2run dev:console
Toggle template hints:
mage2run dev:template-hints
System Information
System info:
mage2run sys:info
List stores:
mage2run sys:store:list
List all URLs:
mage2run sys:url:list
Cron history:
mage2run sys:cron:history
Run specific cron:
mage2run sys:cron:run job_code
Best Practices
Use in Development: n98-magerun2 is primarily designed for development and debugging environments
Regular Updates: Keep n98-magerun2 updated with
mage2run self-updateBackup Before Database Operations: Always backup before running database modification commands
Test Commands: Test commands in development before running in production
Read Help: Use
mage2run help <command>to understand command options and arguments
Tip
You can chain multiple commands using the script command to automate repetitive tasks.
Warning
Be cautious when using database modification commands, especially in production environments. Always create backups first.