Skip to main content
Back to Blog
Server & DevOpsOctober 15, 202410 min read

Upgrading Magento 2 to the Latest Version: A 10 Step-by-Step Guide

A structured 10-step process for upgrading Magento 2 from v2.4.3 to v2.4.7-p3 on Ubuntu, covering system preparation, backups, staging setup, Composer updates, custom module handling, and post-upgrade optimization.

OPS

Upgrading Magento 2 to the Latest Version: A 10-Step Guide

This guide provides a structured 10-step process to upgrade Magento 2 from v2.4.3 to v2.4.7-p3 on an Ubuntu 24 server. Following these steps ensures the e-commerce platform remains secure, optimized, and up-to-date with the latest features.

Step 1: System Preparation

We begin by updating server packages and installing the required PHP version (8.1 or 8.2) for Magento 2.4.7-p3. Keeping the system current enhances stability and compatibility.

sudo apt update && sudo apt upgrade -y
sudo apt install php8.1 php8.1-cli php8.1-fpm php8.1-{common,mbstring,xml,curl,zip,gd,bcmath,intl,soap}

Step 2: Back Up the Magento Store

Backing up both the files and the database is crucial to safeguard data. This enables us to restore the store in case of any issues during the upgrade.

sudo tar -czvf magento_backup.tar.gz /path/to/magento
mysqldump -u <db_user> -p<db_password> <db_name> > magento_backup.sql

Step 3: Set Up a Staging Environment

Testing the upgrade in a staging environment helps avoid disruptions on the live site. Setting up Git in staging can aid in version tracking and reversion if necessary.

cd /path/to/staging/magento
git init
git add .
git commit -m "Initial staging setup for Magento upgrade"

Step 4: Enable Maintenance Mode in Staging

Activate maintenance mode on the staging environment to prevent access during the upgrade process.

php bin/magento maintenance:enable

Step 5: Set Magento Version in Composer

Edit the composer.json file to specify Magento version 2.4.7-p3, then initiate the upgrade. Composer will manage dependency updates accordingly.

composer require magento/product-community-edition=2.4.7-p3 --no-update
composer update

Step 6: Database and System Updates

Run setup commands to synchronize the database, compile DI files, and deploy static content for compatibility with the new version.

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f

Step 7: Update Custom Modules in app/code

If there are custom modules in app/code that are not managed by Composer, we must update them manually to prevent setup:di:compile errors.

Step 8: Conduct Testing in Staging

We perform thorough functionality tests in the staging environment to ensure all features work as expected:

  • Check core functions like browsing, add-to-cart, and checkout.
  • Test extensions and custom themes for compatibility.

Step 9: Upgrade the Live Site

Once the staging environment is verified, we replicate the upgrade process on the live site. Enable maintenance mode and follow the same upgrade steps used on staging.

php bin/magento maintenance:enable

After completing the upgrade, disable maintenance mode:

php bin/magento maintenance:disable

Step 10: Post-Upgrade Monitoring and Optimization

Monitor Logs

tail -f /var/log/magento/system.log
tail -f /var/log/magento/exception.log

Optimize Database

mysqlcheck -o <db_name> -u <db_user> -p

Clear Residual Cache

php bin/magento cache:flush

Benefits of Regular Magento Upgrades

Upgrading Magento regularly brings several key benefits:

  • Enhanced Security: Protect the store and customer data from vulnerabilities.
  • Improved Performance: Experience faster load times and smoother operation.
  • Access to New Features: Stay competitive with the latest Magento features.
  • Better Compatibility: Ensure the store works seamlessly with PHP and server updates.

Troubleshooting Tips

If we encounter issues during the upgrade, consider these tips:

  • Composer Dependency Conflicts: Use the --with-all-dependencies flag if conflicts arise.
  • PHP Compatibility: Confirm PHP 8.1 or 8.2 is installed and compatible with Magento 2.4.7-p3.
  • Custom Module Issues: Ensure custom modules in app/code are updated to avoid errors during setup:di:compile.

By following this 10-step process, we ensure a successful upgrade to Magento 2.4.7-p3 with minimal downtime and maximum reliability.

Need help with this?

Our team handles this kind of work daily. Let us take care of your infrastructure.

Related Articles