Common mistakes in Magento 2 setup
Even before Adobe acquired Magento Commerce, Magento 2 became complex and with colossal applications with hundreds of settings and tens of thousands of files with code. On one hand, it results in a bunch of awesome features which comes out of the box with fresh Magento 2 installation. On the other hand, it makes Magento not a kind of “fire and forget” solution and creates a lot of place for miss-configurations and mistakes.
Today we are going to talk about the most common mistakes in Magento 2 setup which could make your Magento slow.
1. Using wrong hardware setup
If you are not using Magento 2 Cloud solution, it adds a couple of things to worry about. One of them is how to arrange proper infrastructure setup. Magento is not one of the cheapest platforms to host and we recommend you to check with and follow Magento 2 Performance Best Practice and select a proper hosting plan for your website.
2. Not using content delivery network
3. Disabling Magento 2 caches
Magento 2 is a highly extensible and flexible eCommerce solution. The price for this is an extremely complex architecture of data flows and developer configurations. Usage configurations in XML format dramatically reducing site performance. To reduce impact, Magento 2 provides a layer of caching functionality out-of-the-box. Disabling configuration cache altogether with other types of cache could dramatically reduce your website performance.
4. Using built-in full page cache instead of varnish
For some types of Magento 2 caches it is not enough to only keep them enabled. Full Page Cache is one of them. Magento 2 on-premise installation allows you to select between two Caching Application types: Built-in Cache and Varnish Cache. Magento 2 Cloud installation has a 3'rd option available — Fastly CDN. By default, Magento 2 uses Built-in Cache, however, Varnish Cache is more appropriate to use for production applications.
According to Varnish architecture, Magento 2 content pages (Homepage, Category page, Product details page, CMS pages, etc) will be loaded from cache, even without initializing Magento 2 which dramatically decreasing Time to First Byte (TTFB), increasing the throughput of your application and saves server resources.
You can select Varnish as cache application in Admin Panel: Stores -> Settings -> Configuration -> Advanced -> System -> Full Page Cache -> Caching Application.
5. Using flat catalog products and flat catalog category
If you are using the latest versions of Magento 2 you should consider that using Flat tables for Catalog and Product data is disabled.
In older Magento 2 versions Flat Tables are used to optimize the way which Catalog and Product data works. On a low level, Magento 2 stores the price information in a distributed way via the EAV database architectural pattern. Content manager modifies category or product data in Admin Panel and in few minutes, after being transferred to Flat tables via Flat indexer, changes will appear on Magento 2 Storefront.
Nowadays, Adobe does not recommend the usages of Flat Indexes to avoid issues with data synchronization and performance degradation which they could cause.
Data flow with enabled flat tables
You can disable Flats by changing configuration in Admin Panel in: Stores -> Settings -> Configuration -> Catalog -> Catalog -> Storefront.
Magento 2 Flat Tables configuration
We recommend testing the application on a dedicated test environment first, as some 3'rd party extensions could be working only with enabled Flat Tables.
However, the Developer tab could be disabled if you are using Magento 2 in production mode. In this case, you should change these settings in the server terminal via the Magento 2 CLI application.
php bin/magento config:set dev/css/merge_css_files 1php bin/magento config:set dev/css/minify_files 1php bin/magento config:set dev/js/merge_files 1php bin/magento config:set dev/js/minify_files 1
Therefore, we recommend to enable HTTP/2 on your server to optimise work with many HTTP requests on your site.
8. You are not using production mode in the production environment
Magento 2 application could be run in 3 different modes: development, default, and production. However, only the ‘production’ mode should be used for the live website. Development and default modes dramatically decrease site performance and developer mode could show technical details about your application in the case of an error happening on the frontend.
You could check the current mode of your application via server terminal and Magento 2 CLI application:
php bin/magento deploy:mode:show