How to run Drupal 6 on PHP 7

During the last days I was in need to run Drupal 6 on PHP 7. There were some minor problems, but it works after a few changes within a code. It was a nice surprise that these old software is able to run with newer versions of PHP.

Yes, we all should leave Drupal 6 era and run Drupal 7 or better Drupal 8 (or Backdrop if you like the Drupal 7 way). But the reality often changes things and we have to solve the problems. It was this case. I had to prepare two Drupal 6 powered websites to run on Debian 9 with PHP 7.

The problem with PHP 7 and Drupal 6

Drupal 6 doesn't support PHP 7 out of the box. The problem is there are no updates for this branch since Drupal 8 was released. So I was a little bit sceptic. As soon as I ran Drupal 6 on PHP 7 LAMP stack I saw only white screen in my browser.

Luckily I have a server access and am able to read the Apache's error log. Thanks to it solving this problem takes only a few minutes.

The first problem was with a word break which can't be outside the loop. The second problem I've had facing was ereg() function in Drupal file operation code.

Solution for Drupal 6 and PHP 7

The first problem described above hadn't come from Drupal core. Both websites used the imageapi module which has a file imageapi_gd.module having this construct:

if ($radius == 0) {
return $img; imagedestroy($img);

The solution was simple - commenting out the line with break word.

The second problem was in Drupal 6 core file includes/ The line 1085 includes this construct:

elseif ($depth >= $min_depth && @ereg($mask, $file))

The problem is the ereg() function was deprecated in PHP 5.3.0, and removed in PHP 7.0.0. So my idea was using the preg_match() function instead. The edited line looks like this:

elseif ($depth >= $min_depth && @preg_match('/'.$mask.'/', $file))

And that's all. The two Drupal 6 instances seems to be working without any other problems. Yes, there will be an upgrade to Drupal 8 as soon as possible but the websites are operational for now which is the most important.

Just a note: one of these Drupal 6 websites was attacked, the admin account was compromised, changed e-mail address and password. You should know there are now security patches for a long time so running Drupal 6 is really not a good idea if comes to security questions.

And a tip at the end. There is a Github repository with Drupal 6 changed to be compatible with PHP 7. I haven't tried it yet, but you can give it a try.