Upgrading from Drupal 4 to 5

Since I've upgraded townx.org, I also had to upgrade mooch labs and Rails West Midlands. I've finished this now.

By the way, upgrading from Drupal 4 to Drupal 5 wasn't as straightforward as I'd like. The database upgrades worked for my two simple sites, but I rebuilt the database from scratch for this site, as things didn't quite seem to work when I tried to run update.php. Not sure why. So here was my process:

  • Set up staging.townx.org (domains, new web space etc.).
  • Put an entry in /etc/hosts to point to staging.townx.org (so I don't have to wait for DNS propagation).
  • Copied Drupal 5 install to the staging.townx.org directory.
  • Copied existing database to townxstaging database.
  • Set up connections in sites/staging.townx.org/settings.php to point at townxstaging database.
  • Ran update.php on staging.townx.org (NB you have to set $access_check = TRUE in that file for the script to run). A few things didn't work, possibly because I had a non-standard theme, so a lot of my theme settings didn't work and the page went blank. Tip: If you're upgrading an existing site, set the theme to Bluemarine before you start upgrading. But my database structure did get altered properly.
  • Created another clean database, townxstaging2, pointed settings.php at that, then ran the Drupal install script to create the database structure. staging.townx.org now contained a blank, default Drupal install.
  • Manually installed the modules I need by downloading the versions for Drupal 5 from http://drupal.org. These are the modules I use:
    • Textile: there's not a release for Drupal 5, but CVS HEAD version with a patch works fine.
    • Pathauto: available for Drupal 5.
    • Captcha: available for Drupal 5.
    • CommentRSS: available for Drupal 5. I added my own modification to put links onto nodes.
  • Manually copied over data from a whole slew of tables from townxstaging to townxstaging2 (note that as I'd updated townxstaging, the tables were in the right format for import; this won't work if you're trying to directly import from a Drupal 4 to a Drupal 5 database):
    • blocks: I recreated all the blocks from scratch.
    • boxes: Again, I recreated blocks from scratch, cutting and pasting the text for the boxes I need from my old Drupal to my new one (I really should turn them into one or more modules, probably). Text Link Ads only points you at the Drupal module now, which isn't available for Drupal 5 yet. So I copied over my old box code and modified it a bit to fit the Garland theme.
    • comments: these imported fine.
    • files, file_revisions: These worked fine. I also needed to copy my files directory from my old install into the new one.
    • filters, filter_formats: I had to reconfigure all of my input formats. However, as my nodes still referenced the old IDs for the filter formats, I had to manually fix the IDs in the filter_formats table.
    • menu: This transferred over fine.
    • node, node_comment_statistics, node_revisions: This caused the most hassle, as the ordering of fields in the table has changed between versions. Tip: If you are dumping data out of node_revisions using phpmyadmin, make sure you dump using complete inserts, as this includes the field names in the INSERT statements. Note that you also need to set something in the log field for each record: NULL won't do. So during the export I set the log field to '' for all nodes where the log field wasn't set.
    • sequences: I imported these OK. Tip: Make sure any settings in your new database are overwritten by settings from your old database. Otherwise you get weird insert errors, as Drupal will try to reuse IDs that already exist.
    • system: In the end, I recreated this from scratch, and didn't use any of my old settings. This meant quite a bit of hassle, but it did give my system settings a much-needed spring clean.
    • term_*, vocabulary_*: I just imported all of these.
    • url_alias: Imported fine.
  • Note that I ignored watchdog, session, cache_* etc. (ephemeral stuff). I also ignored variables, and just recreated that through the GUI. Some things I don't use (like contact, forum), so I ignored them. I ignored history too, which you might not be able to do on a site with multiple users.
  • Manually copied my modifications to the page template into the Garland theme. These include some <meta> tags, and some Javascript to run my Blogbeat monitoring.
  • Copy my modified .htaccess file (to run under PHP 5 and redirect some domain names onto others).
  • Once I had staging.townx.org running properly, I moved my old site out the way, moved staging into its place, renamed a few databases, and hey presto, it seems to be working fine.

There were other bits and pieces I've probably missed, but that about sums it up.


Good post

Thank you so much i was needing to switch form 4 to 5 Durpal. =)

Joomla user.

I use Joomla myself and I am familiar with word press but everyone does seem to be going on about Drupal, I am deffo going to give it a try to see what it is like.

Drupal CMS?

I've heard a lot of good impressions about Drupal CMS. Currently I use Joomla, but I'm thinking about switching to Drupal
Is Drupal more complex than Joomla? Probably someone here could tell me in brief what will I gain/loose by switching to Drupal?

I am in very serious

I am in very serious thoughts in these days to put Drupal on for few of my sites. Although it is not an easy application but I read a lot about it. I am going to install Drupal 6 so let's see what happen.

upgrade ready?

I am not sure if I am ready to upgrade as there are times that things would go wrong and then I could not figure it out. But I found this post is very well written, I would like to try to upgrade my new websites! Thanks!

Realtor, You should go for

Realtor, You should go for Drupal 6 now because it is now the latest version since many months.

I am always very afraid of

I am always very afraid of upgraded and other stuff. That's why I hate wordpress because it almost has upgrades each week. Fortunately I am not an old blogger so I have just started blogging with Drupal 6. I love it because there is nothing better than it.


Your last update code is the one I'm looking for. Thanks and regards.

Any chance...

...of publishing the modification to the CommentRSS module to get comment feed links into nodes, please?

Hello Jock. To get the RSS

Hello Jock. To get the RSS feed link on individual nodes, I added a function to the end of the modules/commentrss/commentrss.module file (inside the PHP block) which looks like this:

function commentrss_link($type, $node = 0, $main) {
  $links = array();

  if ($type == 'node') {
    $links['comments_rss'] = array('href' => 'crss/node/'.$node->nid, 'title' => 'comments RSS', 'attributes' => array('title' => t('RSS feed of comments on this post')));

  return $links;

I seem to remember that's all you need to do. NB this works with version 1.12 of the module, but might not work with the latest one (I haven't checked).

hate it

That's why I hate wordpress because it almost has upgrades each week. Fortunately I am not an old blogger so I have just started blogging with Drupal 6. I love it because there is nothing better than it.

Well, I have tried to update

Well, I have tried to update my blogs from Drupal 4 to 6 and I faced some unexpected problems. I decided to lieve my blogs with 4th version...

Upgrade using Fantastico

Upgrading shouldn't be a problem if you have cpanel and Fantastico. Its allways better to backup your database but its very simple using the backup feature on cpanel.

That is really a big Pain.

Although nothing can beat Drupal due to its modules and features but it is really a painful process to upgrade it. I was not able to do so so I had to hire someone to do it for all my sites.

As you can see, I've stuck

As you can see, I've stuck with an old version. In your position, I'd try to go from 4 to 5, then from 5 to 6. 4 to 6 is bound to cause endless pain.

Same here, I just cannot

Same here, I just cannot make any good upgrade, I always get errors that at the end puts my site offline. I think I will install everything again.

Well, it can be very time

Well, it can be very time consuming as you would have to check your modules after your update, but I think it is well worth the time.


I'll give that a go and let you know.

Incidentally, I see you're suffering from another problem I've been battling with - that Captcha tells you you have not entered a correct captcha value even as you load a form for the first time. The only way I've found of fixing that so far is to switch to a module called "MyCaptcha" - http://heine.familiedeelstra.com/mycaptcha-download

I really should upgrade this

I really should upgrade this site and fix the modules, but I am currently subject to immense inertia.