Drupal 10 (release already in June 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: https://github.com/wodby/php/blob/master/8/Dockerfile

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 would anything else.

Step 3: check your code for compatibility

There is a library called PHPCompatibility that can help to check your code:

To your composer.json, add this to require-dev:

composer require phpcompatibility/php-compatibility --dev

Then, add the following in the scripts section. This locates your CodeSniffer files:

"scripts": {
    "post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility",
    "post-update-cmd" : "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility"

 Now run

 composer update --lock

Runnig this composer update --lock will install both PHP CodeSniffer, the PHPCompatibility coding standard and - optionally - the Composer plugin.

This will be the composer feedback:

> "vendor/bin/phpcs" --config-set installed_paths vendor/phpcompatibility/php-compatibility
Using config file: /var/www/html/vendor/squizlabs/php_codesniffer/CodeSniffer.conf

Config value "installed_paths" updated successfully; old value was "../../drupal/coder/coder_sniffer,../../phpc                                                       ompatibility/php-compatibility,../../sirbrillig/phpcs-variable-analysis,../../slevomat/coding-standard"

Now, from your drupal root, you can run the command to check for compatibility. The following command will run test for your custom modules folder

vendor/bin/phpcs -p web/modules/custom --standard=PHPCompatibility --runtime-set testVersion 8.1 --extensions=php,module,install,inc --report-full==./mysite-php8-compatibility.txt

It creates a textfile with a log of compatibility. 

Interesting reads:



Saved you some valuable time?

Received 100 so far from 4 kind contributors.