Drupal 7: How to reset admin password

After several research I tried the following code stored it as a php file in the root directory

saved it as password-reset-admin.php

define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
require_once DRUPAL_ROOT . '/includes/password.inc';
if (isset($_GET['pass']) && !empty($_GET['pass'])) { 
$newhash = user_hash_password($_GET['pass']);
else {
die('Retry with ?pass=PASSWORD set in the URL');
$updatepass = db_update('users') 
'pass' => $newhash,
// 'name' => 'admin',
// 'mail' => '<a href="mailto:yourmail@domain.com'">yourmail@domain.com'</a>;
->condition('uid', '1', '=')
print "Done. Please delete this file immediately!";

And after that access the php file through the following:


It just worked..:) Hope it helps others.

Please make sure you delete the file.


Apache url rewrite – removing .php extension via .htaccess

Add to the .htaccess (make sure the vhost can read htaccess files)

# Avoid listing files, enable multiviews
Options -Indexes -MultiViews
# Enable RewriteEngine
RewriteEngine On
# Don’t rewrite directory names
RewriteCond %{REQUEST_FILENAME} !-d
# Don’t rewrite file names
RewriteCond %{REQUEST_FILENAME} !-f
# Remove .php extension
RewriteRule ^([^\.]+)$ $1.php [NC,L]

The Drupal Kit – List of essential drupal modules for a new installation

  • Drupal core – https://www.drupal.org/project/drupal
  • Chaos tool suite (ctools) – https://www.drupal.org/project/ctools
  • Admin menu – https://www.drupal.org/project/admin_menu
  • Views – https://www.drupal.org/project/views
  • Date – https://www.drupal.org/project/date
  • Token – https://www.drupal.org/project/token
  • Pathauto – https://www.drupal.org/project/pathauto
  • Configure WYSIWYG – http://brusselstech.wordpress.com/2012/11/12/drupal-how-to-set-up-wysiwyg-with-image-uploader/