Magento Optimization Guide
This topic provides instructions for optimizing the performance of your production deployment. This process should be followed by technical users responsible for stores running in production to optimize performance.
- You installed Magento using Composer or a compressed archive
- You will be using this environment to run your live production instance of Magento 2
Server - Software Recommendations
The following is a list of recommended software for production instances in order of impact:
- Varnish cache
- PHP 7
- (Enterprise only) Use the Elasticsearch & Elasticsearch Search Adapter
- Nginx and PHP-FPM
For multi-server deployments or for merchants planning on scaling their business we recommend the following:
- Redis for sessions (from 2.0.6+)
- A separate Redis instance as your default cache
- Do not use this instance for page cache
Server - Composer Optimization
setup:di:compile to generate classes, use composer to update the autoloader.
Run the following composer command to generate an optimized composer class map that supports faster auto-loading.
composer dump-autoload -o
Server - PHP Configuration
We recommend enabling and tuning PHP opcache for maximum performance.
opcache.ini file to include the following:
opcache.enable_cli=1 opcache.memory_consumption=512 opcache.max_accelerated_files=100000 opcache.validate_timestamps=0 opcache.consistency_checks=0
When you fine tune the memory allocation for opcache, take into account the size of Magento’s code base and all your extensions. Magento’s performance team uses the values in the preceding example for testing because it provides enough space in opcache for the average number of installed extensions.
If you are on a low memory machine and you do not have many extensions or customizations installed, use the following settings to get a similar result:
Server - Redis Configuration & Tuning
Consider how sessions are flushed from the cache and your merchants abandoned cart strategy.
Estimate a memory size to fit the total number of effective skus, product pages and content pages you expect will be used.
Magento - Performance Optimizations
Enable these performance optimizations to improve the store front responsiveness of your Magento instance.
Go to the Admin in default of developer mode and change the following settings for store front asset optimization:
Stores -> Configuration -> Advanced -> Developer
|Grid Settings||Asynchronous indexing||Enable|
|CSS Settings||Minify CSS Files||Yes|
|Template Settings||Minify HTML||Yes|
Stores -> Configuration -> Sales -> Sales Emails
|General Settings||Asynchronous Sending||Enable|
System -> Index Management
Set all indexers to “Update by Schedule” mode.
Switching to production mode improves store front responsiveness and prevents long initial page load times that can occur in default mode.
Run the following commands to switch to production mode:
bin/magento setup:static-content:deploy bin/magento setup:di:compile bin/magento deploy:mode:set -s production bin/magento index:reindex bin/magento cache:flush