Skip to content
STAGE33R

Guides · Server software · 7 steps · reviewed

Magento 2 security patches and upgrades with Composer, without breaking the shop

Magento stores are a regular target for card skimmers, and the fix is almost always an update that was available for weeks. The risk of updating is real too, because extensions can break. This routine puts the backup and a test in front of the change.

  1. Know what you run

    Note the Magento version, PHP version, search engine and the list of third-party extensions. Check the release notes and PHP/OpenSearch requirements of the target version before touching anything.

    bin/magento --version
    php -v
    composer show 2>/dev/null | grep -vi magento/ | head -n 40
  2. Back up files and database

    Take both, and keep them off the server. Test that the dump is readable.

    tar czf ~/magento-files-$(date +%F).tgz /var/www/magento
    mysqldump --single-transaction --quick DB_NAME | gzip > ~/magento-db-$(date +%F).sql.gz
  3. Try it on a copy first

    Restore the backup to a separate server and run the update there. Extensions that are not compatible show up here, not on the live shop.

  4. Enable maintenance mode

    This keeps customers out of a half-updated store.

    bin/magento maintenance:enable
  5. Upgrade with Composer

    Set the target version, update, and let Composer resolve the dependencies. Read any conflict message: it usually names the extension to update.

    composer require magento/product-community-edition=TARGET_VERSION --no-update
    composer update
  6. Apply database changes and rebuild

    Run the schema upgrade, recompile, deploy static content and clear caches.

    bin/magento setup:upgrade
    bin/magento setup:di:compile
    bin/magento setup:static-content:deploy -f
    bin/magento cache:flush
  7. Disable maintenance mode and test

    Place a test order, check the admin login, search and payment return. Watch the error log for a few minutes.

    bin/magento maintenance:disable
    tail -n 50 var/log/exception.log

Common mistakes

  • Updating the live shop without a restored copy to test on.
  • Ignoring the PHP version requirement of the new release.
  • Forgetting to flush the opcache or restart PHP-FPM after the upgrade.
  • Leaving the admin on the default path, with no IP restriction or two-factor.

How to undo it

Enable maintenance mode, restore the code and the database dump from the backup, run cache:flush, then disable maintenance mode. Keep the backup until the new version has run for a few days.

Sources

Commands are for Debian and Ubuntu unless noted. Test on a copy first and keep a backup: you are responsible for changes on your own systems.