Drupal 10 (release end 2022) needs PHP 8. It will not be possible to run Drupal 10 on PHP 7 or earlier.

Current compatibility:

  • Drupal 8 does not support PHP8, you will have issues
  • Starting from Drupal 9.3, Drupal is compatible with both > PHP7.1 and > PHP8.1

Step by step upgrade guide

Step 1: upgrade everything to latest versions + database updates

The first thing you would need to do is take everything to the latest versions. This means: the latest Drupal core (> 9.3) and packages

composer update

Step 2: upgrade your host machine / VM / containers to PHP 8

There are several ways you can host your local projects. 

Here is a Docker image for PHP8:

For most Docker / Vagrant solutions (like Lando, Drupal VM, etc.) this is frequently configurable in a file. Here’s an example for Lando:

  php: '8.1'

Now restart your container / virtual machines!

Step 3: set your composer.json PHP version

Now that the PHP version of your server is updated, it’s time to make the change in your composer.json file. 

Change the PHP version in the require section of composer.json. 

    "require": {
        "php": ">=8.1",
        "drush/drush": "^10.3",

In the config section of composer.json change the PHP version. Platform config will help make sure that your host PHP version and project PHP version stay in their lane.

    "config": {
        "discard-changes": true,
        "sort-packages": true,
        "platform": {
            "php": "8.1"

Then you can just run 

composer update --with-all-dependencies

Just like you are used to.

Step 3: Check your code for compatibility

Below commands will check for both current/future Drupal AND current PHP version deprecations

Require drupal-check

composer require  --dev phpstan/phpstan phpstan/extension-installer mglaman/phpstan-drupal phpstan/phpstan-deprecation-rules

Run the command to check deprecations in your custom modules

Check deprecations in custom modules and theme

phpstan analyze web/modules/custom
phpstan analyze web/themes/custom

This will return a list in this form:

PHPstan results

------ --------------------------------------------------------------------

  Line   mymodule/src/Form/CustomConfigForm.php

 ------ --------------------------------------------------------------------

  160    Call to deprecated function file_save_data():

         in drupal:9.3.0 and is removed from drupal:10.0.0. Use

           \Drupal\file\FileRepositoryInterface::writeData() instead.

  264    Method Drupal\vito\Form\CustomConfigForm::FormatExcelLine() should

         return array but return statement is missing.

 ------ --------------------------------------------------------------------   

Line   mymodule/mymodule.module

 ------ ---------------------------------------------

  123    Call to deprecated function date_sunrise().

 ------ ---------------------------------------------

Fix the errors and check again.

Some typical errors you will encounter:

Interesting reads:


Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!