Drupal 10 (release end 2022) needs PHP 8. It will not be possible to run Drupal 10 on PHP 7 or earlier.
Current compatibility:
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
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:
config:
php: '8.1'
Now restart your container / virtual machines!
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.
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:
PHP 8.1 is recommended for Drupal 9.4 and 10https://t.co/buJByabj2m
— Stef Van Looveren (@stefvanlooveren) February 16, 2022