Command-line upgrade

You can upgrade your Magento application from the command line if you installed the software by:

  • Downloading the metapackage using composer create-project.
  • Installing the compressed archive.

Do not use this method to upgrade if you cloned the Magento 2 GitHub repository. Instead, see Update the Magento application for upgrade instructions.

Prerequisites

Complete the following prerequisites to prepare your environment before starting the upgrade process:

  • Complete the Update and upgrade checklist—To avoid possible errors during installation or upgrading, complete the Update and upgrade checklist.
  • Set the pub/ directory root—If you set the Magento root directory to pub/, create another subdomain or docroot that uses the Magento installation directory as its root, and run the System Upgrade utility using that subdomain.
  • Check PHP and environment settings—Verify that your PHP and other environment settings are compatible with the system requirements.
  • Switch to maintenance mode—To prevent access to your store while it’s being upgraded, switch your store to maintenance mode:

    1
    
      bin/magento maintenance:enable
    

    See Enable or disable maintenance mode for additional options.

    Optionally, you can create a custom maintenance mode page.

Upgrade using the command line

Using the more manual process of upgrading via the command line allows you to track and control exactly what’s being changed in the upgrade.

Backup composer.json

Backup the existing composer.json file in the Magento installation directory.

Manage packages

Specify needed packages and remove any unneeded ones before proceeding with the upgrade.

Deactivate the Magento Open Source update (for edition upgrade only)

Optional—If you are upgrading from Magento Open Source to Magento Commerce, deactivate the Magento Open Source update:

1
composer remove magento/product-community-edition --no-update

Specify Magento packages

Indicate the Magento packages, both the edition (community or enterprise) and the version (2.3.2), that you want to upgrade to.

Magento Open Source:

1
composer require magento/product-community-edition=2.3.2 --no-update

Magento Commerce:

1
composer require magento/product-enterprise-edition=2.3.2 --no-update

To see the full list of available 2.3 version:

Magento Open Source:

1
composer show magento/product-community-edition 2.3.* --all | grep -m 1 versions

Magento Commerce:

1
composer show magento/product-enterprise-edition 2.3.* --all | grep -m 1 versions

Specify additional packages

1
composer require --dev allure-framework/allure-phpunit:~1.2.0 friendsofphp/php-cs-fixer:~2.13.0 lusitanian/oauth:~0.8.10 magento/magento-coding-standard:~1.0.0 magento/magento2-functional-testing-framework:~2.3.14 pdepend/pdepend:2.5.2 phpunit/phpunit:~6.5.0 sebastian/phpcpd:~3.0.0 squizlabs/php_codesniffer:3.3.1 --sort-packages --no-update

Remove unused packages

1
composer remove --dev sjparkinson/static-review fabpot/php-cs-fixer --no-update

Update autoload

Open composer.json and edit the "autoload": "psr-4" section to include "Zend\\Mvc\\Controller\\": "setup/src/Zend/Mvc/Controller/":

1
2
3
4
5
6
7
8
9
"autoload": {
    "psr-4": {
        "Magento\\Framework\\": "lib/internal/Magento/Framework/",
        "Magento\\Setup\\": "setup/src/Magento/Setup/",
        "Magento\\": "app/code/Magento/",
        "Zend\\Mvc\\Controller\\": "setup/src/Zend/Mvc/Controller/"
    },
    //...
}

Modify the Magento updater

Optional—If the Magento updater is installed, modify it (it is located in the update/ directory):

  1. Backup the update/ directory.
  2. Create a Composer project.

    Magento Open Source version 2.3.2:

    1
    
     composer create-project --repository=https://repo.magento.com magento/project-community-edition=2.3.2 temp_dir --no-install
    

    Magento Commerce version 2.3.2:

    1
    
     composer create-project --repository=https://repo.magento.com magento/project-enterprise-edition=2.3.2 temp_dir --no-install
    

    If you need to use a repository that contains non-public packages, such as internal sandboxes, change the URL in --repository accordingly.

  3. Remove the old update/ directory and move temp_dir/update/ to the update/ directory:

    1
    
    rm -rf update
    
    1
    
    mv temp_dir/update .
    
    1
    
    rm -rf temp_dir
    

Update metadata

Update the "name", "version", and "description" fields in the composer.json file as needed.

Updating the metadata in composer.json file is entirely superficial, not functional.

Apply updates

1
composer update

Clean the Magento cache

After applying an update, you must clean the cache.

1
bin/magento cache:clean

Manually clear caches and generated content

Clear the var/ and generated/ subdirectories:

1
rm -rf var/cache/*
1
rm -rf var/page_cache/*
1
rm -rf generated/code/*

If you use a cache storage other than the filesystem, such as Redis or Memcached, you must manually clear the cache there too.

Update the database schema and data

1
bin/magento setup:upgrade

Disable maintenance mode

1
bin/magento maintenance:disable

Restart Varnish

Optional—If you use Varnish for page caching, restart it:

1
service varnish restart

Check your work

Open your storefront URL in a web browser to check whether the upgrade was successful. If your upgrade was unsuccessful, your storefront will not load properly.

If the application fails with a We're sorry, an error has occurred while generating this email. error:

  1. Reset file system ownership and permissions as a user with root privileges.
  2. Clear the following directories:
    • var/cache/
    • var/page_cache/
    • generated/code/
  3. Check your storefront in your web browser again.

Alternatives

There are alternatives methods that automate parts of the upgrade process:

  1. Upgrade using the script (semi-automated process) Upgrading using the script process is a bit easier and less intensive if you have not made updates to values that the script affects. If you previously made updates, do not upgrade using the script. The script will override your updates.
  2. EXPERIMENTAL: Upgrade using the custom Composer plugin We are developing a custom Composer plugin that enhances the semi-automated upgrade process.

The upgrading scenario is the same for each of these options. Both use Composer and a command line interface.

All scenarios require that you comply with the Prerequisites.