Setting up and configuring an e-commerce store on Magento 2 can be a complex task. To maximize the potential of this powerful platform, it’s essential to implement best practices for Magento 2 configuration.
This blog post will offer insights into Magento 2 configuration best practices, covering cron jobs, indexers, caches, and more. By following these practices, you can ensure that your Magento 2 store runs smoothly, attracts more visitors, and converts them into loyal customers. Get ready to unlock the full potential of Magento 2 and take your e-commerce store to new heights.
1. Cron Jobs
- Log in as, or switch to, the file system owner.
- Change to your Commerce installation directory.
- Run command
bin/magento cron:install [–force]
To view the crontab, enter the following command as the file system owner
A sample follows:
#~ MAGENTO START c5f9e5ed71cceaabc4d4fd9b3e827a2b * * * * * /usr/bin/php /var/www/html/magento2/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/html/magento2/var/log/magento.cron.log #~ MAGENTO END c5f9e5ed71cceaabc4d4fd9b3e827a2b
Remove the Commerce crontab
Run cron from the command line
bin/magento cron:run [--group="<cron group name>"] Ex: bin/magento cron:run --group index bin/magento cron:run --group default
By default, the cron information can be found at <install_directory>/var/log/cron.log.
Update on Save
- Config in System > Tools > Index Management
- The Update on Save mode immediately indexes whenever your catalog or other data changes
Update on Schedule (Recommend)
- Config in System > Tools > Index Management
- The Update on Schedule mode stores information about data updates and performs indexation by portions in the background through a specific cron job
- System > Tools > Cache Management
We highly recommend using Varnish, as it is an efficient production page cache solution.
4. Asynchronous email notifications
- Go to Stores > Settings > Configuration > Sales > Sales Emails > General Settings > Asynchronous Sending
- Enabling the “Asynchronous email notifications” setting moves processes that handle checkout and order processing email notifications to the background
5. Asynchronous order data processing
- Configuration in Stores > Settings > Configuration > Advanced > Developer > Grid Settings > Asynchronous indexing
- There can be times when intensive sales on a storefront occur when Commerce is performing intensive order processing. You can configure Commerce to distinguish these two traffic patterns on the database level to avoid conflicts between read and write operations in the corresponding tables. You can store and index order data asynchronously. Orders are placed in temporary storage and moved in bulk to the Order Management grid without any collisions.
See more information: Enable scheduled grid updates and reindexing
6. Client side optimization settings
- Configuration in Stores -> Configuration -> Advanced -> Developer
This option also brings lazy evaluation, as all JS is loaded as text. It initiates analysis and evaluation of code only after specific actions are triggered on the page. However, this setting is not recommended for stores where the first page load time is extremely critical, because all JS content will be loaded on the first call.
|Grid Settings||Asynchronous indexing||Enable|
|CSS Settings||Minify CSS Files||Yes|
|Template Settings||Minify HTML||Yes|
7. Bundling tips
- We recommend that you use third-party tools for minification and bundling (like r.js). Commerce built-in mechanisms are not optimal and are shipped as fallback alternatives.
- Activating the HTTP2 protocol can be a good alternative to using JS bundling. The protocol provides pretty much the same benefits.
- We do not recommend using deprecated settings like merging JS and CSS files, as they were designed only for synchronously-loaded JS in the HEAD section of the page. Using this technique can cause bundling and require JS logic to work incorrectly.
8. Database maintenance schedule
- We recommend performing periodic database backups for your Staging and Production instances. Due to the I/O intensive nature of backup operations, you may encounter slower backups and potential issues. Running database processes for multiple environments at the same time may potentially run slower due to contention for available resources.
- For better performance, schedule your backups to run in succession, one at a time, at off-peak times. This method avoids I/O contention and reduces time to complete, especially for smaller instances, larger databases, and so on.
- For example, we recommend scheduling a backup of your Production database followed up by the Staging database when your stores encounter lower visits.
By following these best practices, you can streamline your store management processes, improve customer experiences, and ultimately drive the success of your Magento 2 store. Continuous monitoring, optimization, and adaptation to emerging trends are crucial for maintaining a competitive edge in the ever-evolving e-commerce landscape.