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:
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 --apcu
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:
We recommend enabling the PHP APCu extension for maximum performance. This extension caches file locations for opened files, increasing performance for Magento server calls (including pages, ajax calls, and endpoints).
apcu.ini file to include the following:
extension=apcu.so [apcu] apc.enabled = 1
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 storefront responsiveness of your Magento instance.
Go to the Admin in default of developer mode and change the following settings for storefront 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|
Stores -> Index Management
Set all indexers to “Update on Schedule” mode.
Switching to production mode improves storefront 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 deploy:mode:set production