Skip to main content

Update Drupal Core using composer

How to upgrade drupal core with composer

Note: Desable anty virus first

Summary

  1. Check status report & address any issue or any outdated module/themes
  2. Make a backup
  3. Put the site in Maintanance Mode
  4. Using terminal & go to the property folder eg: mysite/web
  5. Check if any update available: composer outdated "drupal/*"
  6. Check using core-recommended or drupal/core: composer show drupal/core-recommended
  7. If you are using drupal/core-recommended: composer update "drupal/core-*" --with-all-dependencies
    With this command - drupal will update to the latest version
  8. Run php.update
  9. Deactivate Maintenance Mode

Details

  1. Put the site in Maintanance Mode
  2. Open Cpanel & under Advanced, click Terminal
  3. Type 'cd public_html'
  4. After that type 'cd Yourfolderpagename' or 'cd Yourfolderpagename/web'
  5. Check if any update available: composer outdated "drupal/*"
  6. Check Status report under Reports in the Administrative GUI. Fix all errors and warnings before proceeding.
  7. Update all modules or themes
  8. Make a backup of files & database - so you can roll back if anything goes wrong
    Optionally sometimes an update includes changes to default.settings.php or default.services.yml files. 
    * Make a backup copy of your settings.php file, with a different file name
    * Make a copy of the new default.settings.php file, and name the copy settings.php (overwriting your previous settings.php file)
    * Copy the custom and site-specific entries from the backup you made into the new settings.php file. You will definitely need the lines giving the database information, and you will also want to copy in any other customizations you have added.
  9. Verify whether the project uses drupal/core-recommended or drupal/core: README
    Run: composer show drupal/core-recommended
    *If drupal/core-recommended is installed, this command returns information about the package
    *If drupal/core-recommended is not installed, this command returns "Package drupal/core-recommended not found"
  10. Update the composer - Better to update the composer forst before proceed with update: run composer update
  11. Update Drupal core code:
    9.1) If you are using drupal/core-recommended: composer update "drupal/core-*" --with-all-dependencies
    9.2) If you are not using drupal/core-recommended but instead only drupal/core: composer update drupal/core --with-dependencies
    Note: To simulate the update, and show you what would happen, without actually changing anything, add --dry-run
  12. Run php.update
  13. Deactivate Maintenance Mode

NOTE: Update to a specific version of core
In general, we recommend that you do not specify a specific version of Drupal core when updating, unless you know that you want to pin to a specific version.

Warning: If you pin your site to a specific core version, that version will be added to the lock file, and future updates will not go past this version. Re-run the require command as specified below to return to an 'unpinned' version of core.

Unpinning from a specific version of core
If you are running a pinned version of Drupal core, and want to update your site to another version. You can unpin your core version, and update to the latest version of Drupal. To unpin your version of Drupal, run this command: composer require drupal/core-recommended drupal/core-composer-scaffold drupal/core-project-message --update-with-all-dependencies


Known issues and workarounds

1) Problem: composer shows drupal/core updated but Status report does NOT show updated version
Summary: The composer update command can silently fail causing a mismatch between what version of drupal/core Composer shows versus what Drupal's Status report page shows. Removing the core directory and running composer install should resolve the problem.

Detailed explanation: If you run the composer update command above and composer outdated "drupal/*" returns Everything up to date, and the version returned with composer show drupal/core | grep versions outputs the expected updated version, but visiting Reports > Status report shows the previous version (check core/lib/Drupal.php to see what the const VERSION value is -- this is what will display on Status report), then composer update has silently failed. To fix, remove the core directory and then run composer install. For example:

rm -rf web/core/
composer install

This will re-download the updated version's core directory. Reload the Status report page to see the new version. (You may need to clear/rebuild caches (drush cache:rebuild or Configuration > Development > Performance > Clear all caches) to see the change.)

2) Problem: drupal/core not updated with composer update
If you run the composer update command above but drupal/core is not updated, there might be another dependency holding back the Drupal upgrade. You can check for blocking dependencies using the command composer prohibits (synonym: composer why-not). For example, if you are trying to upgrade from 8.4.5 to 8.5.0, you can run composer prohibits drupal/core 8.5.0, and it should give a list of dependencies blocking the upgrade. Update those dependencies along with drupal/core and it should work (e.g. composer update drupal/core "symfony/*" --with-dependencies).

*If you have updated composer, and you find you have some dependencies that only work with older composer/installer versions, then include composer/* in the above command to fetch composer dependencies as well:

composer update drupal/core "drupal/core-*" "composer/*" --with-all-dependencies

Composer update problems are often related to abandoned composer templates or bad settings in composer.json. Make sure you are using a composer template like the one suggested in Chapter 3.5. of the Drupal User Guide "Using Composer to Download and Update Files". See Add Composer to existing sites for a step by step guide to manually adding composer to existing Drupal 8 sites that were previously installed without Composer.

In case of errors and warnings occurring in the middle of the update process, it is recommended to read them carefully and search in the issue queues for possible solutions before going on. In case of fatal errors, it is always recommended to stop the updates and restart the whole process from scratch by using the backup recommended you made before.


Read more:

Google AdSense
client = ca-pub-2898279488603899
slot = 9058461004
format = auto