Knowledge Base

How to optimize Magento

This article describes specific steps you can take to optimize a Magento site.

Optimizing Magento

Magento includes several configuration options that you can use to help improve your site's speed and responsiveness. The procedures below show how to configure these options so they are optimized for high performance.

The settings described in this article apply to Magento 2 and 1.9. Earlier Magento versions may not include some of these settings.

If you configure the settings as described below and your site's performance is still not at the level you want, there are additional options:

Cron job

By default on shared servers, the Magento cron job runs every 15 minutes. However, this frequent interval is unnecessary and can lead to performance issues that not only affect your account, but other accounts as well. For step-by-step instructions about how to configure Magento's cron jobs for optimal performance and help avoid potential slowdowns, please see this article.

Logging

Magento's default log setting can cause databases to grow very large, affecting site performance. By optimizing Magento's log settings and cleaning the database log tables, you can significantly reduce database sizes and improve site performance. For step-by-step instructions about how to do this, please see this article.

Caching

Magento includes several built-in caches, and you should make sure that they are all enabled for your store. To do this, follow these steps:

  1. Log in to Magento using your administrator account, and then:
    • For Magento 2, on the left sidebar, click SYSTEM, and then click Cache Management.
    • For Magento 1.9, on the top menu bar, click System, and then click Cache Management.
  2. Under Cache Storage Management, confirm that the status for all of the caches is set to ENABLED.

    If a cache is not enabled, select the check box for the cache type, in the list box select Enable, and then click Submit.
Local modules
The following optimization only applies to Magento 1.9.

Custom modules are stored in Magento's app/code/local directory. If there are no files in this directory (or if the local directory does not even exist), you can instruct Magento to ignore the directory, which can improve performance.

To do this, open the app/etc/local.xml file in your preferred text editor, and then set the <disable_local_modules> tag to true as shown:

<disable_local_modules>true</disable_local_modules>

To re-enable local modules, set the <disable_local_modules> tag to false.

Apache optimizations

Magento's .htaccess file contains some Apache optimizations that are disabled by default. By enabling these optimizations, you can help decrease page load times for your store.

Compression

The Apache mod_deflate module enables you to compress output. This both saves bandwidth and ensures faster page download times. To enable output compression for Magento, follow these steps:

  1. Open the .htaccess file in your preferred text editor.
  2. Uncomment the lines in the mod_deflate text block as follows:
    <IfModule mod_deflate.c>
    
    ############################################
    ## enable apache served files compression
    ## http://developer.yahoo.com/performance/rules.html#gzip
    
     # Insert filter on all content
     SetOutputFilter DEFLATE
     # Insert filter on selected content types only
     AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
    
     # Netscape 4.x has some problems…
     BrowserMatch ^Mozilla/4 gzip-only-text/html
    
     # Netscape 4.06-4.08 have some more problems
     BrowserMatch ^Mozilla/4\.0[678] no-gzip
    
     # MSIE masquerades as Netscape, but it is fine
     BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    
     # Don't compress images
     SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    
     # Make sure proxies don't deliver the wrong content
     Header append Vary User-Agent env=!dont-vary
    
    </IfModule>
    
  3. Save your changes to the .htaccess file. The changes take effect immediately.
Browser caching

The Apache mod_expires module enables you to instruct web browsers how long to cache certain types of content. This both saves bandwidth and ensures faster page download times. To enable browser caching directives for Magento, follow these steps:

  1. Open the .htaccess file in your preferred text editor, and then:
    • For Magento 2, uncomment the lines in the mod_expires text block as follows:
      <IfModule mod_expires.c>
      
      ############################################
      ## Add default Expires header
      ## http://developer.yahoo.com/performance/rules.html#expires
      
       ExpiresDefault "access plus 1 year"
       ExpiresByType text/html A0
       ExpiresByType text/plain A0
      
      </IfModule>
      
    • For Magento 1.9, uncomment the lines in the mod_expires text block as follows:

      <IfModule mod_expires.c>
      
      ############################################
      ## Add default Expires header
      ## http://developer.yahoo.com/performance/rules.html#expires
      
       ExpiresActive On
       ExpiresDefault "access plus 1 week"
      
      </IfModule>
      
  2. Save your changes to the .htaccess file. The changes take effect immediately.
JavaScript and CSS files

You can reduce your store's page load times by minimizing the number of HTTP requests required to load a page. One way to do this is to merge Magento's JavaScript and CSS files into single files.

Magento 2

To merge and minify JavaScript and CSS files on Magento 2, follow these steps:

  1. Log in to Magento using your administrator account.
  2. On the left sidebar, click STORES, and then under Settings, click Configuration.
  3. Cilck ADVANCED, and then click Developer.
  4. Click JavaScript Settings, and then in the Merge JavaScript Files list box, select Yes.
  5. In the Minify JavaScript Files list box, select Yes.
  6. Click CSS Settings, and then in the Merge CSS Files list box, select Yes.
  7. In the Minify CSS Files list box, select Yes.
  8. Click Save Config.
    It can be hard to debug JavaScript and CSS files when they are merged and minified. If you are doing development work or need to troubleshoot a problem, disable the options in steps 4 to 7. Magento will split the JavaScript and CSS files back into multiple files.
Magento 1.9

To merge JavaScript and CSS files on Magento 1.9, follow these steps:

  1. Log in to Magento using your administrator account.
  2. On the top menu bar, click System, and then click Configuration.
  3. In the Configuration pane on the left side, scroll down the page, and then under ADVANCED, click Developer.
  4. Click JavaScript Settings, and then in the Merge JavaScript Files list box, select Yes.
  5. Click CSS Settings, and then in the Merge CSS Files list box, select Yes.
  6. Click Save Config.
    It can be hard to debug JavaScript and CSS files when they are merged. If you are doing development work or need to troubleshoot a problem, disable the options in steps 4 and 5. Magento will split the JavaScript and CSS files back into multiple files.
Flat catalogs

By default, Magento uses its own Entity Attribute Value (EAV) model to store customer and product information. Although this method is flexible, it may result in slower and more complex SQL queries.

Flat catalogs are an alternative to EAV. In flat catalogs, Magento merges product and category data into single tables, as opposed to the multiple tables for EAV. Doing this often improves database performance and response time.

You should experiment with flat catalogs to see if they improve your own store's performance. Not all store configurations will benefit from using flat catalogs.
Magento 2

To enable flat catalogs for your store on Magento 2, follow these steps:

  1. Log in to Magento using your administrator account.
  2. On the left sidebar, click SYSTEM, and then click Index Management.
  3. Select the Product Flat Data check box.
  4. Select the Category Flat Data check box.
  5. In the Actions list box, select Update on Save, and then click Submit.
  6. On the left sidebar, click STORES, and then click Configuration.
  7. Click CATALOG, and then click Catalog.
  8. Click Storefront.
  9. In the Use Flat Catalog Category list box, select Yes.
  10. In the Use Flat Catalog Product list box, select Yes.
  11. Click Save Config.
  12. Flush the Magento cache:
    • On the left sidebar, click SYSTEM, and then click Cache Management.
    • Click Flush Cache Storage.
    • Click Flush Magento Cache.
Magento 1.9

To enable flat catalogs for your store on Magento 1.9, follow these steps:

  1. Log in to Magento using your administrator account.
  2. On the top menu bar, click System, and then click Index Management.
  3. Select the check box for Product Flat Data.
  4. Select the check box for Category Flat Data.
  5. In the Actions list box, select Reindex Data, and then click Submit.
  6. On the top menu bar, click System, and then click Configuration.
  7. In the Configuration pane on the left side, under CATALOG, click Catalog.
  8. Click Frontend.
  9. In the Use Flat Catalog Category list box, select Yes.
  10. In the Use Flat Catalog Product list box, select Yes.
  11. Click Save Config.
  12. Flush the Magento cache:
    • On the top menu bar, click System, and then click Cache Management.
    • Under Cache Storage Management, click Flush Cache Storage.
404 errors

When a web browser requests a page or resource that does not exist on the server, a 404 Not Found error occurs. Magento replaces the server's default 404 Not Found page with its own custom page. This means that every time a 404 Not Found error occurs, the Magento application runs, increasing CPU load.

To help reduce load on the server, you should make sure that your Magento store does not contain links to nonexistent resources.

Module output

You can disable the output from any unused modules. To do this, follow these steps:

  1. Log in to Magento using your administrator account, and then:
    • For Magento 2, on the left sidebar, click STORES, and then click Configuration. Click ADVANCED, and then click Advanced.
    • For Magento 1.9, on the top menu bar, click System, and then click Configuration. In the Configuration pane on the left side, scroll down the page, and then under ADVANCED, click Advanced.
  2. Under Disable Modules Output, locate the module output you want to disable, and then select Disable.
  3. Click Save Config.

    This procedure only disables the output a module generates—it does not disable the module itself. To disable a module completely:

    • For Magento 2, you can use the command-line interface (CLI) to disable modules. For example, to disable the Magento_Authorizenet module, type the following command from the directory where you installed Magento:
      bin/magento module:disable Magento_Authorizenet

      For more information about how to use the Magento 2 CLI, please see this article.

    • For Magento 1.9, open the app/etc/modules/module_name.xml file, where module_name represents the name of the module you want to disable. In the module_name.xml file, set the <active> tag to false as shown:

      <active>true</active>

      To re-enable the module, set the <active> tag to true.

Developer debugging and logging
The following optimization only applies to Magento 1.9.

Magento includes several options to help developers debug and troubleshoot problems. These options can consume system resources and negatively affect performance, so they are disabled by default.

You should only enable these options if you need to troubleshoot a specific problem. To verify that these options are disabled for your store, follow these steps:

  1. Log in to Magento using your administrator account.
  2. On the top menu bar, click System, and then click Configuration.
  3. In the Configuration pane on the left side, scroll down the page, and then under ADVANCED, click Developer.
  4. Click Debug.
  5. Confirm that the Profiler list box is set to No.
  6. Click Log Settings.
  7. Confirm that the Enabled list box is set to No.
  8. Click Save Config.

 

More Information

To view the official Magento documentation, please visit http://www.magentocommerce.com/knowledge-base.