I would like to call the menu_rebuild() function, but I am not sure of where exactly paste the code snippet.

I can't find the update.php file anywhere in my local instance.

The reason I would like to attempt this is that I deleted all the nodes, but they are still appearing under the menu structure.

  • do you want to rebuild Drupal menu after update or what?
    – Aboodred1
    Commented Jan 28, 2013 at 6:13
  • update.php will be in drupal root folder i.e /var/www/htdocs/drupalAnd modifying it is a bad idea. Could you please add more details as to why you want to call menu_rebuild ?
    – GoodSp33d
    Commented Jan 28, 2013 at 6:16
  • Aboodred1, yes, I would like to rebuild drupal menu after deleting all the nodes. 2-Stroker, drupal.stackexchange.com/questions/58606/…
    – user12804
    Commented Jan 28, 2013 at 6:26
  • @user12804, Are you sure they are node-related menus? If so, I already answered in the other question.
    – Sithu
    Commented Jan 28, 2013 at 8:07

7 Answers 7


Create a file with the following content and simply drop in the Drupal root directory. Let's say menu-rebuild.php. Run it http://example.com/menu-rebuild.php

define('DRUPAL_ROOT', getcwd());
require_once './includes/bootstrap.inc';

  • It may be easier to run this using Devel
    – mbomb007
    Commented Sep 23, 2019 at 14:43

Drupal 7

If you're using drush, you may run:

drush eval 'menu_rebuild();'

If won't work, see: How to do menu rebuild when having PHP Fatal error?

Drupal 6

drush php-eval 'drupal_rebuild_theme_registry()'


If you're using memcached, you've to restart it.

On Linux: /etc/init.d/memcached restart

On OS X (if using Homebrew): brew services restart memcached

  • vote up for the correct drush commands to do that easely, but you definitely should add that in some cases you need to empty the corresponding database tables before like mentioned by @Valk above
    – nilsun
    Commented Nov 17, 2014 at 20:56

Open the database schema, then delete all contents of menu_links and menu_router tables with the following SQL queries:

DELETE FROM menu_links;
DELETE FROM menu_router;

Then run http://example.com/update.php. It will call menu_rebuild(), which will populate these tables with 'fresh' data. It worked for me after a "PHP Fatal Error: Out of memory" turned some of my menus into a mess.

But be aware, that it will wipe out all you custom menus which you will have to rebuild manually. To avoid it you may play a bit with deleting of some selected records from menu_router and menu_links, but for me it didn't work well.

And don't forget to back-up your database and site directory before deleting contents from the tables.

  • 2
    vote up for the needed additional info, that sometimes you DEFINITELY need to empty the correspnding database tables before menu_rebuild. THis is confirmed here from long term experiences ...
    – nilsun
    Commented Nov 17, 2014 at 20:57

A couple of different ways:

  1. Call menu_rebuild() from hook_update_N
  2. Edit and save a menu settings form from Drupal admin.
  3. From the command line, with drush: drush cc menu
  • Thank you. Can I do this without drush as well?
    – user12804
    Commented Jan 28, 2013 at 6:28
  • Yes, any of the above 3 methods will work by itself. Commented Jan 28, 2013 at 6:33
  • Re: Edit and save a menu link from Drupal admin. Doesn't work, already tried that a few times...
    – user12804
    Commented Jan 28, 2013 at 7:47
  • Yes, that one was meant for the menu settings page. You can also call menu_cache_clear_all() to rebuild menu cache Commented Jan 28, 2013 at 7:52

Going to admin/config/development/performance and clicking on the "Clear all caches" button will cause the menu to be rebuilt, as well as clear template, block, page, etc. cache.

  • Thanks Penten, I tried that a number of times, but no luck. The deleted nodes are still appearing in the Navigation menu structure :(
    – user12804
    Commented Jan 28, 2013 at 6:27

Alternative way is to set variable:

variable_set('menu_rebuild_needed', TRUE);

This will trigger the menu_rebuild();


To fix the admin menu use in SQL and note that as Valk stated above it will remove all customization from your administration management menu. After you run it clear your cache adn the management menu will be rebuilt to its default settings.

Here is the SQL query:

DELETE FROM menu_links WHERE menu_name='management' 
  • to rebuild menu mostly becomes needed when something is really broken and Drupal can'T fix it in the middle. That'S why I would rather recommend Valks method because a complete reset is a better answer for such question if no more details are provided WHAT is broken.
    – nilsun
    Commented Nov 17, 2014 at 20:59

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.