notes.tyrone.dev

Add an admin user to a Craft site2021-02-25

The Craft shell is only available if the yii2-shell package is installed:

composer require --dev yiisoft/yii2-shell

Start the shell:

./craft shell

Execute the command:

Craft::$app->elements->saveElement(new \craft\elements\User([
  'username' => '<username>',
  'email' => '<email>',
  'newPassword' => '<password>',
  'admin' => true,
  'passwordResetRequired' => false,
]));