Home RESOURCES Our Step by Step Guide to Upgrade Magento 2.1.x to 2.2.6
Category
Web Development
READ TIME
5 minutes
One Stop Media

Our Step by Step Guide to Upgrade Magento 2.1.x to 2.2.6

The latest Magento update is here. The largest e-commerce platform on the market is expanding its features, here’s what it means for your business;

Magento’s updates includes flexible modular architecture making it a scalable platform that has a wider range of control options allowing for the development of user-friendly and search engine-friendly Magento websites.

Compatibility with the latest technology such as PHP 7 means faster loading times enhancing the customer experience on your site whilst using fewer server resources meaning lower hosting costs for you.

Store management is made easier through updates to visual merchandising, multi-currency and store functionality. Customer engagement is enriched through Magento’s capacity to identify and retain loyal customers, as well as employing updated promotion tools. Additionally the pipeline deployment system means production system downtime for site updates is minimised.

Security vulnerability has been addressed as a priority as well as overall site performance.

The checkout process has been improved by Magento, this means that shopping carts are no longer erased by reloading the page. Order placing times have also been amended to be more efficient.

A significant modification in Magento’s newest model is its B2B competency, making it easier for merchants whose primary customers are companies. The B2B commerce function also includes a flexible API that integrates with a range of ERP solutions from Magento partners. Under this new model companies can create and manage their own accounts, each with their own teams and level of permission.

To begin enjoying these modified features follow our complete guide to updating Magento 2.1.x to 2.2.6.

Ensure everything is backed up including your files and database before attempting to upgrade. This will allow you to go back if you encounter any difficulties.

1.Backup your Magento files and database by running the commands below:

mysqldump -u USER -p DATABASE | gzip > DATABASE.sql.gz

tar -cvzf backup_$(date +%m-%d-%Y).tar.gz public_html/

2. Continue upgrading Magento from 2.1.x to 2.2.6 by running the following commands:

• First, enable maintenance mode by executing the following command. This will prevent users from interacting with the site while the update is happening:

php bin/magento maintenance:enable

• Before we update Magento we need to make sure composer has the latest version on its config file:

composer require magento/product-community-edition 2.2.6 --no-update

• Then run the following command to update Magento to the latest version which is 2.2.6

if error come

then direct update the version in composer.json file as

composer update

• After updating we need to remove cached files in following folders so that Magento can regenerate new files. The following commands will recursively remove cached files:

rm -rf var/cache/*

rm -rf var/page_cache/*

 rm -rf var/generation/*

chmod +x bin/magento

• Also, Magento has built-in commands to clear cache, if you think the above has not deleted the files for you try executing the following two commands.

php bin/magento cache:clean

php bin/magento cache:flush

• Finally to complete the update run the command below to make sure database tables will upgrade to support the latest Magento version.

php bin/magento setup:upgrade

• When everything is complete, simply run the command below to re-compile all the classes in Magento. This is a required step as it will regenerate all the classes for new modules.

php bin/magento setup:di:compile

• Then just disable maintenance mode and let visitors enjoy the new and more secure Magento 2.2.6.

php bin/magento maintenance:disable

3. Problems may occur when completing the update, a common error is in the file:

/vendor/magento/framework/Serialize/Serializer/Json.php
This can be resolved by replacing the file with the following:
Json.php2.94 KB

is_serialized($string))
        {
            //$string = $this->serialize($string);
            $string = json_encode(unserialize($string));
        }
        $result = json_decode($string, true);
        if (json_last_error() !== JSON_ERROR_NONE) {
             throw new InvalidArgumentException('Unable to unserialize value.');
        }
        return $result;
    }
    function is_serialized($value, &$result = null)
    {
        // Bit of a give away this one
        if (!is_string($value))
        {
            return false;
        }
        // Serialized false, return true. unserialize() returns false on an
        // invalid string or it could return false if the string is serialized
        // false, eliminate that possibility.
        if ($value === 'b:0;')
        {
            $result = false;
            return true;
        }
        $length = strlen($value);
        $end    = '';
        switch ($value[0])
        {
            case 's':
                if ($value[$length - 2] !== '"')
                {
                    return false;
                }
            case 'b':
            case 'i':
            case 'd':
                // This looks odd but it is quicker than isset()ing
                $end .= ';';
            case 'a':
            case 'O':
                $end .= '}';
                if ($value[1] !== ':')
                {
                    return false;
                }
                switch ($value[2])
                {
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    case 6:
                    case 7:
                    case 8:
                    case 9:
                        break;
                    default:
                        return false;
                }
            case 'N':
                $end .= ';';
                if ($value[$length - 1] !== $end[0])
                {
                    return false;
                }
                break;
            default:
                return false;
        }
        if (($result = @unserialize($value)) === false)
        {
            $result = null;
            return false;
        }
        return true;
    }
}
?>

When you again open the backend you can see the Magento with the updated version

4. Using Redis in conjuction with Magento can also cause this error.

The command redis-cli flushall is able to resolve this.

5. Be aware that plugins may cause errors, in order to avoid this ensure you have updated your current plugins or alternatively disabled them from your store.

In order to run a successful e-commerce business being on top of technological developments is half the battle. As the e-commerce world continues to explode, updates are integral to stay competitive and offer your customers the best experience possible.
To take your e-commerce business to the next level, contact one of our experts at One Stop Media.