I have tried every possible ways to create a user account using only a single PHP file without writing a module. I want to create a portal in which visitors can subscribe or register themselves and do something after they logged in. I have also a mobile application (Android and iOS) in which my app users can register (subscribe) and use the app in their mobile phone. Both the web application and the mobile application use the same API to create a Drupal 8 user. Is there anyone who help me out to achieve this?

2 Answers 2


If you want a single php file you can use a drush shell script:

#!/usr/bin/env drush

use Drupal\user\Entity\User;

    $user = User::create(['name' => 'testuser', 'status' => TRUE]);

For more information see https://github.com/drush-ops/drush/blob/master/docs/shellscripts.md

A better approach might be to use REST, see https://www.drupal.org/node/2754633


Eyosiyas Tadele, Like 4k4 said, You don't even need to write any PHP code, not even single file and definitely not a module if you are using Drupal 8 core REST module.

Here is a sample Drupal 8 Android app https://github.com/onedrupal/One-Drupal-Android that uses core REST API to POST node. Similarly you can POST to user registration API.

You can use https://www.drupal.org/project/restui contrib module to enable and configure these APIs once you have enabled, you can export as a config yml file if you want to move the REST API config from dev environment to prod environment like the yml file at https://cgit.drupalcode.org/one_api/tree/config/install/rest.resource.entity.user.yml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.