Command-line upgrade
Command-line upgrade
You can upgrade Magento from the command line if you installed the software using any of the following:
- Downloaded the metapackage using
composer create-project
- Installed the compressed archive
- If you cloned the Magento 2 GitHub repository, you cannot use this method to upgrade; instead, see Update the Magento application.
- If you configured Magento use use
pub
as its root directory, see the next section. - If you're upgrading to Magento 2.1 (including a Release Candidate) from Magento 2.0.7 or earlier and you installed sample data, see Command-line upgrade to Magento 2.1 with sample data instead of this topic.
- If you're upgrading to version 2.1, see Upgrade to Magento version 2.1 (June 22, 2016).
- If you're upgrading from Magento Open Source or Magento Commerce 2.0.0 or 2.0.1, you must first perform the tasks discussed in the <a href="href="http://devdocs.magento.com/guides/v2.0/release-notes/tech_bull_201-upgrade.html">Technical Bulletin (1/28/16)</a>.
Pre-upgrade checklist
Before you continue, to avoid errors during your installation or update, make sure you verify all of the following:
- You set up a Magento file system owner and shared that owner’s group with the web server user group
- Your cron jobs are set up and running
- Set a value for DATA_CONVERTER_BATCH_SIZE
- File system permissions are set properly
Do not continue without performing these checks. Failure to do so could result in errors.
Set a value for DATA_CONVERTER_BATCH_SIZE
Magento 2.2 includes security enhancements that requires some data to be converted from serialized data format to JSON encoded format. This conversion occurs during the upgrade and it can take a long time, depending on how much data is in your Magento database.
One or more fields in the following tables are affected: sales_order
, sales_order_payment
, quote
, quote_payment
, core_config_data
, magento_reward_history
, url_rewrite
, salesrule
, and catalogrule
. (This is not a complete list.)
If you have a large amount of data, you can improve performance by setting the value of an environment variable, DATA_CONVERTER_BATCH_SIZE
. By default, it’s set to a value of 50,000.
To set the variable, before the upgrade starts enter the following command as the Magento file system owner in a bash shell prompt:
export DATA_CONVERTER_BATCH_SIZE <value>
For example,
export DATA_CONVERTER_BATCH_SIZE 100000
After your upgrade completes, you can unset the variable as follows:
unset DATA_CONVERTER_BATCH_SIZE
DATA_CONVERTER_BATCH_SIZE
requires memory; avoid setting it to a very large value (approximately 1GB) without testing it first.
Magento file system owner and group
The Magento file system owner group must have write access to Magento directories and files.
Cron jobs are running
Magento requires three cron jobs, all running as the Magento file system owner.
To verify your cron jobs are set up properly, enter the following command as the Magento file system owner:
crontab -l
Results similar to the following should display:
* * * * * /usr/bin/php /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/magento2/update/cron.php >> /var/www/magento2/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/magento2/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log
Another symptom of cron not running is the following error in the Magento Admin:
To see the error, you might need to click System Messages at the top of the window as follows:
For details, see Set up cron.
File system permissions
For security reasons, Magento requires certain permissions on the file system. Permissions are different from ownership. Ownership determines who can perform actions on the file system; permissions determine what the user can do.
Directories in the Magento file system must be writable by the Magento file system owner’s group.
To verify your file system permissions are set properly, either log in to the Magento server or use your hosting provider’s file manager application.
For example, enter the following commands on a Linux system if the Magento application is installed in /var/www/html/magento2
:
ls -al /var/www/html/magento2
A sample result follows:
In the preceding example, the Magento file system owner is magento_user
. Directories in the Magento file system have drwxrwx---
permissions (775) and files have -rw-rw-rw-
permissions (664).
To get more detailed information, you can optionally enter the following command:
ls -al /var/www/html/magento2/pub
Because Magento deploys static file assets to subdirectories of pub
, it’s a good idea to verify permissions and ownership there as well.
For more information, see File system permissions and ownership.
Prerequisite: pub
directory root
This section applies to you only if you set the Magento root directory to <your Magento install dir>/pub
. If you did not do this, skip this section and continue with the next section.
-
For the upgrade, create another subdomain or docroot that uses the Magento installation directory as its root.
Run the System Upgrade utility using that subdomain.
-
Use the following procedure to upgrade Magento using the command line.
Put your store in maintenance mode
To prevent access to your store while it’s being upgraded, put your store in maintenance mode.
You can optionally create a custom maintenance mode page.
- Log in to your Magento server as, or switch to, the Magento file system owner.
-
Enter the following command:
php <your Magento install dir>/bin/magento maintenance:enable
For additional options, see Enable or disable maintenance mode.
Upgrade using the command line
- Log in to your Magento server as, or switch to, the Magento file system owner.
-
Change to the directory in which you installed the Magento software.
For example,
cd /var/www/html/magento2
-
Enter the following commands in the order shown:
composer require <product> <version> --no-update composer update
For example, to upgrade to Magento Open Source version 2.0.11, enter:
composer require magento/product-community-edition 2.0.11 --no-update composer update
To upgrade to Magento EE version 2.0.11, enter:
composer require magento/product-enterprise-edition 2.0.11 --no-update composer update
If an error displays about a missing
.gitignore
files, see the <a href="http://devdocs.magento.com/guides/v2.0/release-notes/tech_bull_201-upgrade.html#resolution2>Technical Bulletin (1/28/16)</a>. - If prompted, enter your authentication keys.
-
Manually clear
var
subdirectories:rm -rf <Magento install dir>/var/cache/* rm -rf <Magento install dir>/var/page_cache/* rm -rf <Magento install dir>/generated/code/*
-
Update the database schema and data:
php bin/magento setup:upgrade
-
Put your storefront online (that is, cancel maintenance mode):
php bin/magento maintenance:disable
-
Restart Varnish if you use it for page caching.
service varnish restart
-
Access your storefront.
The following error might display:
We're sorry, an error has occurred while generating this email.
If so, perform the following tasks:
- Reset file system ownership and permissions as a user with
root
privileges. -
Clear the following directories and try again:
<your Magento install dir>/var/cache <your Magento install dir>/var/page_cache <your Magento install dir>/generated/code
- Reset file system ownership and permissions as a user with