The n98 magerun cli tools provides some handy tools to work with Magento from command line.
Latest Release
Development Branch
The tools will automatically be tested for multiple PHP versions (5.3, 5.4, 5.5). It's currently running in various Linux distributions and Mac OS X. Microsoft Windows is not fully supported (some Commands like db:dump or install are excluded).
The tool partially works with Magento 2 development branch.
There are two ways to install the tools:
or if you have problems with SSL certificate:
You can make the .phar file executable.
If you want to use the command system wide you can copy it to /usr/local/bin.
Debian / suhosin:
On some Debian systems with compiled in suhosin the phar extension must be added to a whitelist.
Add this to your php.ini file:
You don't like the filename?
Just rename it to whatever you want.
https://github.com/netz98/n98-magerun/wiki/Install-from-source-with-Composer
Since version 1.1.0 we deliver a self-update script within the phar file:
$ n98-magerun.phar self-update
If file was installed system wide do not forget "sudo".
See it in action: http://youtu.be/wMHpfKD9vjM
All commands try to detect the current Magento root directory. If you have multiple Magento installations you must change your working directory to the preferred installation.
https://github.com/netz98/n98-magerun/wiki/Commands
You can list all available commands by:
$ n98-magerun.phar list
If you don't have the .phar file installed system wide you can call it with the PHP CLI interpreter:
php n98-magerun.phar list
Global config parameters:
- --root-dir
Force Magento root dir. No auto detection.
- --skip-config
Do not load any custom config.
- --skip-root-check
Do not check if n98-magerun runs as root.
Loads basic customer info by email address.
Creates a new customer/user for shop frontend.
Example:
This will delete a customer by a given Id/Email, delete all customers or delete all customers in a range of Ids.
Examples:
$ n98-magerun.phar customer:delete 1 # Will delete customer with Id 1
$ n98-magerun.phar customer:delete mike@example.com # Will delete customer with that email
$ n98-magerun.phar customer:delete --all # Will delete all customers
$ n98-magerun.phar customer:delete --range # Will prompt for start and end Ids for batch deletion
Generate dummy customers. You can specify a count and a locale.
Supported Locales:
- cs_CZ
- ru_RU
- bg_BG
- en_US
- it_IT
- sr_RS
- sr_Cyrl_RS
- sr_Latn_RS
- pl_PL
- en_GB
- de_DE
- sk_SK
- fr_FR
- es_AR
- de_AT
List customers. The output is limited to 1000 (can be changed by overriding config). If search parameter is given the customers are filtered (searchs in firstname, lastname and email).
- Website parameter must only be given if more than one websites are available.
Arguments
setting Only output value of named setting
Dumps configured Magento database with mysqldump.
- Requires MySQL CLI tools
Arguments
filename Dump filename
Options
- --add-time
Adds time to filename (only if filename was not provided)
- --compression (-c)
Compress the dump file using one of the supported algorithms
- --only-command
Print only mysqldump command. Do not execute
- --print-only-filename
Execute and prints not output except the dump filename
- --no-single-transaction
Do not use single-transaction (not recommended, this is blocking)
- --human-readable
Use a single insert with column names per row.
- --stdout
Dump to stdout
- --strip
Tables to strip (dump only structure of those tables)
- --force (-f)
Do not prompt if all options are defined
Only the mysqldump command:
Or directly to stdout:
Use compression (gzip cli tool has to be installed):
Dumps your database and excludes some tables. This is useful i.e. for development.
Separate each table to strip by a space. You can use wildcards like * and ? in the table names to strip multiple tables. In addition you can specify pre-defined table groups, that start with an @ Example: "dataflow_batch_export unimportant_module* @log
Available Table Groups:
- @log Log tables
- @dataflowtemp Temporary tables of the dataflow import/export tool
- @stripped Standard definition for a stripped dump (logs, sessions and dataflow)
- @sales Sales data (orders, invoices, creditmemos etc)
- @customers Customer data
- @trade Current trade data (customers and orders). You usally do not want those in developer systems.
- @search Search related tables (catalogsearch)
- @development Removes logs, sessions and trade data so developers do not have to work with real customer data
Extended: https://github.com/netz98/n98-magerun/wiki/Stripped-Database-Dumps
See it in action: http://youtu.be/ttjZHY6vThs
Imports an SQL file with mysql cli client into current configured database.
- Requires MySQL CLI tools
- Arguments:
filename Dump filename
- Options:
--compression (-c) The compression of the specified file --only-command Print only mysql command. Do not execute
Use decompression (gzip cli tool has to be installed):
Optimize "human readable" dump:
Opens the MySQL console client with your database settings from local.xml
- Requires MySQL CLI tools
Create currently configured database
Drops the database configured in local.xml.
- Requires MySQL CLI tools
Executes an SQL query on the current configured database. Wrap your SQL in single or double quotes.
If your query produces a result (e.g. a SELECT statement), the output of the mysql cli tool will be returned.
- Requires MySQL CLI tools
- Arguments:
query SQL query
- Options:
--only-command Print only mysql command. Do not execute
See the most important MySQL variables of your Magento instance.
This command is useful to print important server status information about the current database.
Creates a ZIP archive with media folder content.
If strip option is set, the following folders are excluded:
- js (combined js files)
- css (combined css files)
- catalog/product/cache
Index by indexer code. Code is optional. If you don't specify a code you can pick a indexer from a list.
Since 1.75.0 it's possible to run mutiple indexers by seperating code with a comma.
i.e.
If no index is provided as argument you can select indexers from menu by "number" like "1,3" for first and third indexer.
Loops all Magento indexes and triggers reindex.
Dumps merged XML configuration to stdout. Useful to see all the XML.
Config of catalog module:
See module order in XML:
Write output to file:
- Arguments:
path The config path value The config value
- Options:
--scope The config value's scope (default: "default" | Can be "default", "websites", "stores") --scope-id The config value's scope ID (default: "0") --encrypt Encrypt the config value using local.xml's crypt key
- Arguments:
path The config path
- Options:
--scope The config value's scope (default, websites, stores) --scope-id The config value's scope ID --decrypt Decrypt the config value using local.xml's crypt key --update-script Output as update script lines --magerun-script Output for usage with config:set --format Output as json, xml or csv
- Help:
If path is not set, all available config items will be listed. path may contain wildcards (*)
Example:
- Arguments:
path The config path
- Options:
--scope The config scope (default, websites, stores) --scope-id The config value's scope ID --all Deletes all entries of a path (ignores --scope and --scope-id)
Search system configuration descriptions.
Cleans expired cache entries.
If you would like to clean only one cache type:
If you would like to clean multiple cache types at once:
If you would like to remove all cache entries use cache:flush
Run cache:list command to see all codes.
If no code is specified, all cache types will be disabled. Run cache:list command to see all codes.
If no code is specified, all cache types will be enabled. Run cache:list command to see all codes.
This command let you investigate what's stored inside your cache. It prints out a table with cache IDs.
Prints stored cache entry by ID.
If value is serialized you can force a pretty output with --unserialize option.
Toggle demo store notice
ID can be e-mail or username. The command will attempt to find the user by username first and if it cannot be found it will attempt to find the user by e-mail. If ID is omitted you will be prompted for it. If the force parameter "-f" is omitted you will be prompted for confirmation.
Releases the password lock on an admin (leave blank to unlock all admins)
Toggle admin notifications.
If no option is provided it toggles the mode on every call.
Provides info like the edition and version or the configured cache backends.
Lists all store views.
Lists base urls for each store.
Lists all websites.
Lists all cronjobs defined in config.xml files.
Runs a cronjob by code.
If no job argument is passed you can select a job from a list. See it in action: http://www.youtube.com/watch?v=QkzkLgrfNaM
Last executed cronjobs with status.
Examples:
- Create a list of product urls only:
- Create a list of all products, categories and cms pages of store 4 and 5 separating host and path (e.g. to feed a jmeter csv sampler):
- The "linetemplate" can contain all parts "parse_url" return wrapped in '{}'. '{url}' always maps the complete url and is set by default
Runs all setup scripts (no need to call frontend). This command is useful if you update your system with enabled maintenance mode.
Runs setup scripts incrementally. (no need to call frontend). This command runs each new setup script individually in order to increase the transparency of the setup resource system, and reduce the chances of a PHP failure creating an invalid database state.
Compares module version with saved setup version in core_resource table and displays version mismatch.
- If a filename with --log-junit option is set the tool generates an XML file and no output to stdout.
Changes the version of one or all module resource setups. This command is useful if you want to re-run an upgrade script again possibly due to debugging. Alternatively you would have to alter the row in the database manually.
Setup argument default is "all resources" for the given module.
Removes the entry for one or all module resource setups. This command is useful if you want to re-run an install script again possibly due to debugging. Alternatively you would have to remove the row from the database manually.
Setup argument default is "all resources" for the given module.
- Checks missing files and folders
- Security
- PHP Extensions (Required and Bytecode Cache)
- MySQL InnoDB Engine
Hide/Show CMS Banners
Publishes a page by page id and revision.
Useful to automatically publish a page by a cron job.
Opens PHP interactive shell with initialized Magento Admin-Store.
See it in action: http://www.youtube.com/watch?v=zAWpRpawTGc
The command is only available for PHP 5.4 users.
Toggle debug template hints settings of a store
Toggle debug template hints blocks settings of a store
Toggle settings for shop frontend:
Toggle for admin area:
Exports saved database translation data into a file.
Toggle profiler for debugging a store:
Activate/Deactivate system.log and exception.log for a store:
Show size of a log file:
Activate/Deactivate MySQL query logging via lib/Varien/Db/Adapter/Pdo/Mysql.php
Generate Script for attributes:
i.e.
Currently only catalog_product entity type is supported.
List all EAV attributes:
View the data for a particular attribute:
Remove an attribute:
You can also remove multiple attributes in one go if they are of the same type
PhpStorm Code Completion -> Meta file generation.
Prints count of reports in var/reports folder.
Resolves the given type and grouped class name to a class name, useful for debugging rewrites.
Example:
Allow usage of symlinks for a store-view:
Global scope can be set by not permitting store_code parameter:
Creates an empty module and registers it in current Magento shop:
Code-Pool defaults to local.
Example:
* --modman option creates a new folder based on vendorNamespace and moduleName argument. Run this command inside your .modman folder.
- --add-all option add blocks, helpers and models.
- --add-readme Adds a readme.md file to your module.
- --add-composer Adds a composer.json to your module.
- --author-email Author email for composer.json file.
- --author-name Author name for composer.json file.
Enable or disable a module in app/etc/modules/*.xml by name or codePool:
Examples:
Hint
If --codepool option is specified all modules in the codepool are affected.
Lists all installed modules with codepool and version
Lists all registered class rewrites.
sh
$ n98-magerun.phar dev:module:rewrite:list [--format[="..."]]
Lists all duplicated rewrites and tells you which class is loaded by Magento. The command checks class inheritance in order of your module dependencies.
- If a filename with --log-junit option is set the tool generates an XML file and no output to stdout.
Show list of modules which given module depends on
Show list of modules which depend from module
Lists all registered observer by type.
Type is one of "adminhtml", "global", "frontend".
Lists all frontend themes
Find duplicate files (templates, layout, locale, etc.) between two themes.
- originTheme default is "base/default".
Example:
- If a filename with --log-junit option is set the tool generates an XML file and no output to stdout.
List and find connect extensions by a optional search string:
- Requires Magento's mage shell script.
- Does not work with Windows as operating system.
Installs a connect extension by package key:
If the package could not be found a search for alternatives will be done. If alternatives could be found you can select the package to install.
- Requires Magento's mage shell script.
- Does not work with Windows as operating system.
Downloads connect extensions by package key:
- Requires Magento's mage shell script.
- Does not work with Windows as operating system.
Upgrade connect extensions by package key:
- Requires Magento's mage shell script.
- Does not work with Windows as operating system.
Since version 1.1.0 we deliver a Magento installer which does the following:
- Downloads Magento by a list of git repos and zip files (mageplus, magelte, official community packages).
- Tries to create database if it does not exist.
- Installs Magento sample data if available (since version 1.2.0).
- Starts Magento installer
- Sets rewrite base in .htaccess file
Interactive installer:
Unattended installation:
Example of an unattended Magento CE 1.7.0.2 installation:
Additionally, with --noDownload option you can install Magento working copy already stored in --installationFolder on the given database.
See it in action: http://youtu.be/WU-CbJ86eQc
Uninstalls Magento: Drops your database and recursive deletes installation folder.
Please be careful: This removes all data from your installation.
--installationFolder is required and if you do not enter it you will be prompted for it. This should be your project root, not the Magento root. For example, If your project root is /var/www/site and Magento src is located at /var/www/site/htdocs, you should pass /var/www/site to the command, or if you are currently in that particular directory you can just pass "." Eg:
If you omit the -f, you will be prompted for confirmation.
If you need autocompletion for all n98-magerun commands you can start with "shell command".
Run multiple commands from a script file.
Example:
# Set multiple config
config:set "web/cookie/cookie_domain" example.com
# Set with multiline values with "\n"
config:set "general/store_information/address" "First line\nSecond line\nThird line"
# This is a comment
cache:flush
Optionally you can work with unix pipes.
It is even possible to create executable scripts:
Create file test.magerun and make it executable (chmod +x test.magerun):
#!/usr/bin/env n98-magerun.phar script
config:set "web/cookie/cookie_domain" example.com
cache:flush
# Run a shell script with "!" as first char
! ls -l
# Register your own variable (only key = value currently supported)
${my.var}=bar
# Let magerun ask for variable value - add a question mark
${my.var}=?
! echo ${my.var}
# Use resolved variables from n98-magerun in shell commands
! ls -l ${magento.root}/code/local
Pre-defined variables:
- ${magento.root} -> Magento Root-Folder
- ${magento.version} -> Magento Version i.e. 1.7.0.2
- ${magento.edition} -> Magento Edition -> Community or Enterprise
- ${magerun.version} -> Magerun version i.e. 1.66.0
- ${php.version} -> PHP Version
- ${script.file} -> Current script file path
- ${script.dir} -> Current script file dir
Variables can be passed to a script with "--define (-d)" option.
Example:
It's possible to define multiple values by passing more than one option.
You can organize your scripts in a repository. Simply place a script in folder /usr/local/share/n98-magerun/scripts or in your home dir in folder <HOME>/.n98-magerun/scripts.
Scripts must have the file extension .magerun.
After that you can list all scripts with the script:repo:list command. The first line of the script can contain a comment (line prefixed with #) which will be displayed as description.
If you want to execute a script from the repository this can be done by script:repo:run command.
Script argument is optional. If you don't specify any you can select one from a list.
Copy the file bash_complete to n98-magerun.phar in your bash autocomplete folder. In my Ubuntu system this can be done with the following command:
A commandline tool autocompletion XML file for PHPStorm exists in subfolder autocompletion/phpstorm. Copy n98_magerun.xml into your phpstorm config folder.
Linux: ~/.WebIde50/config/commandlinetools
You can also add the XML content over settings menu. For further instructions read this blog post: http://blog.jetbrains.com/webide/2012/10/integrating-composer-command-line-tool-with-phpstorm/
https://github.com/netz98/n98-magerun/wiki/Add-custom-commands
Create the yaml config file ~/.n98-magerun.yaml. Now you can define overwrites. The original config file is config.yaml in the source root folder.
Change of i.e. default currency and admin users:
Create the yaml config file ~/.n98-magerun.yaml. Now you can define overwrites. The original config file is config.yaml in the source root folder.
Add your repo. The keys in the config file follow the composer package structure.
Example:
commands:
N98\Magento\Command\Installer\InstallCommand:
magento-packages:
- name: my-magento-git-repository
version: 1.x.x.x
source:
url: git://myserver/myrepo.git
type: git
reference: 1.x.x.x
extra:
sample-data: sample-data-1.6.1.0
- name: my-zipped-magento
version: 1.7.0.0
dist:
url: http://www.myserver.example.com/magento-1.7.0.0.tar.gz
type: tar
extra:
sample-data: sample-data-1.6.1.0
- Add new commands.
- Send me some proposals if you miss anything.
- Create issues if you find a bug or missing a feature.
- Symfony2 Team for the great console component.
- Composer Team for the downloader backend and the self-update command.
- Francois Zaninotto for great Faker library.