n98-magerun
netz98 magerun CLI tools for Magento 1
The n98 magerun cli tools provides some handy tools to work with Magento from command line.
Build Status
Latest Release
Development Branch
Development is done in develop branch.
This software is only running with Magento 1.
If you use Magento 2 please use another stable version (
https://github.com/netz98/n98-magerun2).
Compatibility
The tools will automatically be tested for multiple PHP versions. 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).
We test the tool agains this versions:
- Magento 1.9.4.5 PHP 7.2
- OpenMage LTS 20.0.3 PHP 7.3
Installation
There are three ways to install the tools:
Download and Install Phar File
Download the latest stable N98-Magerun phar-file from the file-server:
wget https://files.magerun.net/n98-magerun.phar
or if you prefer to use Curl:
curl -O https://files.magerun.net/n98-magerun.phar
Verify the download by comparing the SHA256 checksum with the one on the website at https://files.magerun.net/:
shasum -a256 n98-magerun.phar
If it shows the same checksum as on the website, you downloaded the file successfully.
Now you can make the phar-file executable:
chmod +x ./n98-magerun.phar
The base-installation is now complete and you can verify it:
./n98-magerun.phar --version
The command should execute successfully and show you the version number of N98-Magerun like:
n98-magerun version 1.97.0 by netz98 new media GmbH
You now have successfully installed Magerun! You can tailor the installation further like installing it system-wide and
enable autocomplete – read on for more information about these and other features.
If you want to use the command system wide you can copy it to /usr/local/bin.
sudo cp ./n98-magerun.phar /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:
suhosin.executor.include.whitelist="phar"
You don’t like the filename?
Just rename it to whatever you want. Or better: create an alias so that the original command name still works. This can
be useful if you exchange scripts that are making use of magerun with other users as the canonical name is
n98-magerun.phar, Some common aliases amongst the user-base are magerun or just mr even.
Install with Composer
Require Magerun within the Magento (or any other) project and you can then
execute it from the vendor’s bin folder:
composer require n98/magerun # ... ./vendor/bin/n98-magerun --version n98-magerun version 1.97.0 by netz98 new media GmbH
Alternative source install:
https://github.com/netz98/n98-magerun/wiki/Install-from-source-with-Composer
Install with Homebrew
First you need to have homebrew installed:
http://brew.sh/
Install homebrew-php tap:
https://github.com/Homebrew/homebrew-php#installation
Once homebrew and the tap are installed, you can install the tools with it:
brew install n98-magerun
You can now use the tools:
$ n98-magerun {command}
Update
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
Autocompletion
Files for autocompletion with Magerun can be found inside the folder res/autocompletion, In
the following some more information about two specific ones (Bash, Phpstorm), there are
more (e.g. Fish, Zsh).
Bash
Bash completion is available pre-generated, all commands and their respective
options are availble on tab. To get completion for an otion type two dashes
(“–“) and then tab.
To install the completion files, copy n98-magerun.phar.bash to your bash
compatdir folder for autocompletion.
On my Ubuntu system this can be done with the following command:
# cp res/autocompletion/bash/n98-magerun.phar.bash /etc/bash_completion.d
The concrete folder can be obtained via pkg-config:
# pkg-config --variable=compatdir bash-completion
Detailed information is available in the bash-completions FAQ:
https://github.com/scop/bash-completion#faq
PHPStorm
A commandline tool autocompletion XML file for PHPStorm exists in subfolder res/autocompletion/phpstorm.
Copy n98_magerun.xml into your phpstorm config folder.
Linux and Mac: ~/.WebIde80/config/componentVersions
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/
Usage / Commands
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.–developer-mode
Instantiate Magento in Developer Mode
Open Shop in Browser
$ n98-magerun.phar open-browser [store]
Customer Info
Loads basic customer info by email address.
$ n98-magerun.phar customer:info [email] [website]
Create customer
Creates a new customer/user for shop frontend.
$ n98-magerun.phar customer:create [email] [password] [firstname] [lastname] [website]
Example:
$ n98-magerun.phar customer:create foo@example.com password123 John Doe base
Delete Customers
This will delete a customer by a given Id/Email, delete all customers or delete all customers in a range of Ids.
$ n98-magerun.phar delete [-a|--all] [-f|--force] [-r|--range] [id]
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
Generate dummy customers. You can specify a count and a locale.
$ n98-magerun.phar customer:create:dummy count locale [website]
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
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).
$ n98-magerun.phar customer:list [--format[="..."]] [search]
Change customer password
$ n98-magerun.phar customer:change-password [email] [password] [website]
- Website parameter must only be given if more than one websites are available.
Print database information
$ n98-magerun.phar db:info [setting]
Arguments
setting Only output value of named setting
Dump database
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
$ n98-magerun.phar db:dump
Only the mysqldump command:
$...