Magento 2 Production Settings

by , , revisited on

We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

Magento 2 server

The fine settings below require a properly configured server, to begin with. At a minimum you need:

  • HTTP/2 capable web server (NGINX)
  • Magento 2 cron setup to run every minute
  • Far Future Expire header on static assets

Admin settings

All the settings below are available in the Magento administration area

Stores -> Configuration -> Advanced -> Developer

Settings Group Setting Value Why?
Grid Settings Asynchronous indexing Enable Avoids the locks that occur when data is saved, and to reduce processing time
CSS Settings Minify CSS Files Yes Self-explanatory
Javascript Settings Minify JavaScript Files Yes Self-explanatory
Javascript Settings Enable JavaScript Bundling No M2 docs state: “Activating the HTTP2 protocol can be a good alternative to using JS bundling”. Moreover, bundling results in huge files which are not used on every page, unless you implement sophisticated r.js stuff
Javascript Settings Merge JavaScript Files No M2 docs state: this is “designed only for synchronously-loaded JS in the HEAD section of the page. Using this technique can cause bundling and requireJS logic to work incorrectly”. HTTP/2 negates the necessity for this as well.
Template Settings Minify HTML Yes
Static Files Settings Sign Static Files Yes Will ensure cache busting for static assets which use Far Future Expiry headers

Stores -> Configuration -> Sales -> Sales Emails

Settings Group Setting Value Why?
General Settings Asynchronous Sending Enable Obviously it’s good to have emails fired by cron. User cancelling the page won’t result in missed emails. Another plus is PHP-FPM pool won’t suffer from waiting on an email to be sent.

Stores -> Index Management

Set all indexers to “Update on Schedule” mode. Configure indexers to run on schedule and in parallel.

Stores -> Settings -> Configuration -> Catalog -> Catalog

Use Flat Catalog Category and Product

Production Mode

Switching to production mode improves storefront responsiveness and prevents long initial page load times that can occur in default mode. Make sure to run the switch to production mode after you have set most of the settings above. In some versions the “Developer” section is not visible after switching to production mode!

Run the following commands to switch to production mode:

bin/magento deploy:mode:set production

The script (for 2.2.4 and above)

Instead of tinkering around the admin area, it is better to run a few commands and be done with it.
Here’s the script to set production-ready Magento settings. Note on --lock-* parameters which are available only with versions 2.2.4 and higher. The --lock-env is for system-specific configuration and the --lock-config is for all environments (e.g. will apply to staging and dev environments because the config value will be written to app/etc/config.php.


bin/magento config:set --lock-env dev/js/minify_files 1
bin/magento config:set --lock-env dev/css/minify_files 1
bin/magento config:set --lock-env dev/css/merge_css_files 1
bin/magento config:set --lock-env dev/js/enable_js_bundling 0
bin/magento config:set --lock-env dev/js/merge_files 0
bin/magento config:set --lock-env dev/static/sign 1
bin/magento config:set --lock-config sales_email/general/async_sending 1
# the following seems like two settings for the same thing, who knows? :)
bin/magento indexer:set-mode schedule
bin/magento config:set --lock-config dev/grid/async_indexing 1
# allow indexers to run in parallel for multistore (>= 2.2.6)
bin/magento indexer:set-dimensions-mode catalog_product_price website

# Ensure Varnish is the FPC application
bin/magento config:set --scope=default --scope-code=0 system/full_page_cache/caching_application 2
# Make cache stay longer, two weeks
bin/magento config:set --scope=default --scope-code=0 system/full_page_cache/ttl 1209600

cachetool opcache:reset
rm -rf ~/.cache/opcache/*

# imports file locked config into the database
bin/magento app:config:import

Server Settings

For a list of server related settings to speed up your Magento 2, have a look at the complete Magento 2 performance checklist.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.