A bit of a pre-flight checklist that you need to go through first and the first
- Confirm that any plugins you're using are available for Craft 4.
- Update the Craft 3 Site to the latest version.
- Update the plugins to the latest version.
- Fix all deprecation warnings. You'll find a list of warnings in admin panel under utilities, deprecation warnings.
- Make sure you don’t have any pending or active jobs in your queue.
- Run
php craft project-config/rebuildand allow any new background tasks to complete. - Update DDEV php to 8.1 and add "php": "8.1" to composer.json.
- Remove
aelvan/imagerplugin ~ddev composer remove aelvan/imager. - Edit your project’s
composer.jsonto require"craftcms/cms": "^4.0.0". - Run
composer update. - Make any required changes to your configuration.
- Run
php craft migrate/all.
- Upgrade
vlucas/phpdotenvplugin to4.0. - Edit your project’s
index.php, replace:
(new Dotenv\Dotenv(CRAFT_BASE_PATH))->load(); with
$dotenv = Dotenv\Dotenv::createMutable(CRAFT_BASE_PATH, '.env');
$dotenv->load();
- Replace all
{%- spaceless %}, with{%- apply spaceless %}. - Replace all
{%- endspaceless %}, with{%- endapply %}. - Edit
templates/_macros.twig,isEditableis not defined in craftcms 4, usecurrentUser and entry is defined. - Twig 3 removed support for the
ifparam in{% for %}tags, they suggested you use|filterinstead. But you can just add an if statement inside the{% for %}. - Edit
templates/_includes/form.twig, replace{% for field in tab.getFields() %}with{% for field in form.getFieldLayout().customFields %}.