Magento 2 | Create new ADMIN user from CLI

This time i need to restore a Magento 2 website from production to local;
After had migrate everything, and loaded a dump of db in my local phpMyAdmin, i had a problem:

I NEED THE ADMINISTRATOR URL AND ADMINISTRATOR USER AND PASSWORD

,
the damn customer haven’t give me that informations, ( and i don’t had remembered to ask for it ).
So for the admin url, navigate from the root of Magento “/app/etc/env.php” and find:


<?php
return array (
  'backend' => 
  array (
    'frontName' => 'admin',
  ),
  'crypt' => 
  array (
    'key' => '12630ca5e6e27b76c7619e6b0b3caaae',
  ),

“frontName => admin” is the string that we needed and it tell that the administrator’s url is /admin/.

Now that we had retrieve the admin url we need to create new user with administrator permits.

Let’s open a terminal windows , navigate to the root of magento site, and add the following command :

php bin/magento admin:user:create --admin-user mys_username --admin-password mypass123 --admin-email andreapizzigalli@gmail.com --admin-firstname john --admin-lastname cage

change mys_username with your username
change mypass123 with your new password
change andrea.pizzigalli@beprime.it with your new email
change john with your first name
change cage with your last name

once you have run the query , if all is right, you have a message :

Created Magento administrator user named mys_username

Now you have the admin url and a administrator user and password.

That’s all