Create Magento 2 admin user from shell/terminal

Submitted by metaharper - 6 years ago

In Magento 1.x, I had to create a PHP workbench script in order to be able to create an admin user from shell or terminal (http://www.magetricks.com/tricks/programmatically-create-new-magento-administrator" ). Thankfully, Magento 2's newly introduce CLI (command-line interface) allows you to do this without writing any code. Here is an example of how I would execute this command to create a new administrator.

// Head over to the webroot for your Magento 2 instance e.g. /var/www/html or maybe /var/www/magento2

// Execute admin:user:create with the appropriate arguments as demonstrated below
php bin/magento admin:user:create --admin-user="John" --admin-password="password" --admin-email="[email protected]" --admin-firstname="John" --admin-lastname="Hancock" 

// bin/magento is a PHP executable file that allows you to issue any number of commands. See: http://devdocs.magento.com/guides/v2.0/install-gde/install/cli/install-cli.html

// You can also setup a PATH command in your bash profile that allow you to execute Magento CLI commands from any directory and not just bin
Learn PHP
comments powered by Disqus
Proudly hosted on Digital Ocean