Magento – General optimization

Magento is one of the most popular CMS for e-commerce. It can handle small and large online stores equally well, with a little optimization. This article will help you prepare your CMS to handle large traffic without losing on speed.

This article will show you standard optimization techniques, suitable for every hosting, even if you are not using the [caching options].

Only when you have completed the general optimization, you can proceed to the second part of the article, which shows you how your CMS can benefit from the Performance hosting tools.


Table of Contents:


General optimization

This article outlines the usual optimizations that can be done in Magento.

Some optimizations are free, some are not paid for now, and some do require upgrades.

Activation of APC

Step 1: Activate APC in the control panel

APC is available for PHP 5.4 and lower

  1. Log in on your control panel
  2. Follow My Products >> Web hosting >> Hosting details
  3. From the left-hand panel go to PHP settings
  4. You are now in the Overview. Check the PHP version.Overview > Check PHP version
  5. Switch to the ON/Off tab.ON/Off tab
  6. Switch on apc.Switch on apc
  7. PHP changes take time. To check if your changes took place switch to the PHP info tab. Look for the APC section. If it is there, you have activated APC successfully.PHP info tab APC section

Step 2: Now configure the user cache, too.

  1. Create an SSH account on the hosting package
  2. For convenience, add SSH keys.
  3. Open a terminal or command prompt and connect. Add those lines in the local.xml (/app/etc/local.xml) file with under the <global> tag:
    <cache>
    <backend>apc</backend>
    <prefix>someprefix</prefix>
    </cache>
    

    Terminal
    /app/etc/local.xml
    local.xml

Step 3: Check if it’s caching! You need the apc.php file. To get it, download the latest installation of APC.

download the latest installation of APC.
apc.php file.

  1. Upload apc.php in your Magento directoryUpload apc.php
  2. Open the apc.php file in your browser. The page will show you file caching information.Open the apc.php file
  3. In your terminal or command prompt, open your apc.php file and edit the ADMINUSERNAME and ADMINPASSWORD values. Save.Terminal
    apc.php file
    Edit username and password
  4. Open apc.php file in your browser again. Navigate to the User Cache Entries tab.User Cache Entries tab
  5. Login with the username and password you just set.Login
  6. You are seeing here the user cache entries.user cache entriesuser cache entries

Gzip and expiration of the cache

Terminal .htaccess

To optimize even further you can use Gzip and the expiration of the cache. Just copy and paste the following code at the bottom of the .htaccess file:

# BEGIN moddeflate

# Insert output filter by type
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml
AddOutputFilterByType DEFLATE application/javascript application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/cgi-php5
AddOutputFilterByType DEFLATE application/cgi-php53
AddOutputFilterByType DEFLATE application/cgi-php54

# Don't compress images, compressed files, docs nor movies
SetEnvIfNoCase RequestURI .(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase RequestURI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase RequestURI .(?:pdf|doc)$ no-gzip dont-vary
SetEnvIfNoCase RequestURI .(?:avi|mov|mp3|mp4|rm)$ no-gzip dont-vary

# END moddeflate

# BEGIN expires
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0

# Set up caching on media files for 1 year
<filesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A29030400
Header append Cache-Control "public"

# Set up caching on media files for 1 week
<filesMatch "\.(gif|jpg|jpeg|png|swf)$">
ExpiresDefault A604800
Header append Cache-Control "public"

# Set up 2 Hour caching on commonly updated files
<filesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"

# Force no caching for dynamic files
<filesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"

# END expires

Activate and setup indexer

You need to stop APC before you proceed to this step and restart it afterwards.

Reindexing rearranges product indexes – from indexes stored in multiple tables into a single table structure. Database queries become simpler and faster.

  1. Open a terminal or command prompt and connect.Terminal
  2. Browse your files to the Shell folder in your installation folder: [Magentofolder]/shell
    [Magentofolder]/shell
  3. Run the following command:
    php indexer.php
    

    Run the command

  4. Now you get to see the options. Enter the following commands:
    1. To rebuild all indexes:
      php indexer.php --reindexall
      

      Run the command

    2. The indexes are rebuilt if relevant changes are stored via the backend:
      php indexer.php --mode-realtime
      

      Enter the command

Cron scheduling via cronjobs

Schedule a cronjob for cron.php to be opened every 5 min via the control panel.

Cron.php is a default file found in the root directory of the Magento webshop installation. It manages the regular automatic performance of essential tasks.

Cron.php

Activating flat catalogs

When Flat catalogs are enabled new single raw catalog tables are created as you go which can be regularly updated via the Magento cron.

  1. Log in your Magento backend to enable flat catalogs
    1. Follow System >> Configuration.System >> Configuration
    2. From there go to Catalog.Catalog
    3. Choose the first topic Frontend.Frontend
    4. Now turn on “Use flat catalog category” and “Use flat catalog products”. (Tip: If it is greyed out, reindex from System >> Index management)"Use flat catalog category" and "Use flat catalog products”
      Save configuration

Optimizations in the .htaccess file

Copy and paste the following code at the bottom of your .htaccess file

Terminal .htaccess file

#Leverage Browser Caching

## EXPIRES CACHING ##

ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"

## EXPIRES CACHING ##
Updated on 30 March 2020

Was this article helpful?

Need Support?
Can't find the answer you're looking for?
Contact Support

Couldn't find a solution?

support_bottom_contact_alt

Our specialists are available 24/7 to provide you with free support. Feel free to contact Joachim and his colleagues via e-mail or by phone.

support_bottom_contact_alt
Joachim Coessens Specialist Support