Skip to main content
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.

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

Magento upgrades can be nerve-wracking -- especially jumping from v2.4.3 to v2.4.7-p3. There are dependency changes, PHP version requirements, and custom modules that may not play nice with the new codebase. We've done this enough times to have a reliable process. Here's the 10-step approach we use on Ubuntu 24 servers.

Step 1: System Preparation

Start by getting the server's packages current and installing the right PHP version. Magento 2.4.7-p3 needs PHP 8.1 or 8.2.

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

Don't skip this. Seriously. Back up both the files and the database before touching anything.

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

Never upgrade production first. Clone the site into a staging environment and initialize Git there for easy rollback.

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

Put staging into maintenance mode so nobody accidentally hits it mid-upgrade.

php bin/magento maintenance:enable

Step 5: Set Magento Version in Composer

Tell Composer which version you're targeting, then let it sort out the dependencies:

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

Step 6: Database and System Updates

Now run the Magento setup commands. This syncs the database schema, compiles DI, and deploys static content.

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

Here's where things often go sideways. Custom modules in app/code that aren't Composer-managed won't update themselves. You'll need to check each one manually -- if they reference deprecated classes or interfaces, setup:di:compile will fail.

Step 8: Conduct Testing in Staging

Go through the site thoroughly:

  • Browse categories, add products to cart, complete a test checkout
  • Check that extensions and custom themes still render and behave correctly
  • Look for any console errors or broken layouts

Step 9: Upgrade the Live Site

Once staging looks good, repeat the same process on production. Enable maintenance mode first:

php bin/magento maintenance:enable

After the upgrade is done and tested, bring it back:

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

Staying current with Magento versions isn't just about new features:

  • Security -- each release patches known vulnerabilities. Falling behind puts customer data at risk.
  • Performance -- newer versions include optimizations that genuinely speed things up
  • Feature access -- new Magento capabilities keep the store competitive
  • Compatibility -- PHP and server software evolve, and old Magento versions eventually stop working with newer stacks

Troubleshooting Tips

Things that commonly go wrong:

  • Composer dependency conflicts -- try adding the --with-all-dependencies flag. It usually resolves version lock issues.
  • PHP version mismatch -- double-check that PHP 8.1 or 8.2 is actually the active version (not just installed)
  • Custom module failures -- if setup:di:compile throws errors, the problem is almost always in app/code. Check the error messages -- they usually point right at the offending class.

That's the process. It's not glamorous, but it works reliably, and having a tested staging step saves you from the kind of surprises that turn a maintenance window into an all-nighter.

Need help with this?

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