How to Update Drupal 8 Using Composer
Keeping Drupal up to date is essential for security, performance, and compatibility. If you’re using Composer to manage your project (which is the recommended way), here’s a step-by-step guide to safely update Drupal 8.
📝 Step 1: Check Your Current Version
Before updating, it’s a good idea to see which version of Drupal core you’re running and if updates are available.
composer show drupal/core-recommended --check
composer outdated "drupal/*"
💾 Step 2: Take Backups
Always back up your site and database before making updates. You can use Drush for this:
drush sql:dump > /root/drush-backups/site-$(date +%F).sql
drush archive-dump > /root/drush-backups/site-archive-$(date +%F).tar.gz
🛠 Step 3: Enable Maintenance Mode
Put the site into maintenance mode so users don’t run into issues while the update is in progress.
drush state:set system.maintenance_mode 1
drush cache:rebuild
🔄 Step 4: Update Drupal Core
Run the Composer update command for core-recommended (which ensures the correct set of dependencies).
composer update drupal/core-recommended --with-dependencies
Then rebuild the cache:
drush cache:rebuild
✅ Step 5: Disable Maintenance Mode
Once the update is complete, bring your site back online:
drush state:set system.maintenance_mode 0
drush cache:rebuild
🔧 Optional Commands
Depending on your setup, you might also find these useful:
-
Update
drupal/core
directly (not always recommended):composer update drupal/core --with-dependencies
-
Update to a specific version:
composer require 'drupal/core-recommended:^8.9' --update-with-all-dependencies
-
Use the development branch (not recommended for production):
composer require drupal/core-recommended:8.9.x-dev --update-with-all-dependencies
That’s it! Your Drupal 8 site should now be running the latest version.
No comments:
Post a Comment