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 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 2: set your composer.json PHP version

Now that all the PHP versions have been updated, it’s time to make the change in your composer.json file. Simply update:

I have PHP version in the require section of composer.json. 

Did you know you can add PHP as an a dependency right in the composer.json file? Well you can! And it’s definitely recommended, as it helps to make sure that you get the right version of other dependencies.

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

and in the config section of composer.json. 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 php --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 95€ so far from 3 kind contributors.