Optimizing Magento

Magento is a very popular eCommerce application. It offers a great deal of customization and abilities from initial install. Here are a few suggestions for optimizing a Magento installation.

Please remember that Magento is extremely resource intensive, and if you are having issues with resource usage on shared, you should consider moving to a dedicated server. VPS accounts are not a satisfactory solution for a busy Magento site, as they often have less resources than our shared accounts.

Changes to .htaccess

Enable Output Compression

In your .htaccess file for Magento you will find a section of text starting with the line, <IfModule mod_deflate.c> and ending at </IfModule>

This section of code can be used to turn on Apache's mod_deflate module, which provides compression for text, css, and javascript. You will want to uncomment (remove the # symbol) multiple lines so that it looks like this:

<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>

 

Note: Some of the lines were word-wrapped by the web browser. You may want to copy and paste to make sure everything is on the correct lines.

 

Enable Expires Headers

First-time visitors to your page have to make several HTTP requests. By using the "Expires" header you make the components  of the requests cacheable. This avoids unnecessary HTTP requests on subsequent page views.

You want to find the area of the .htaccess file that starts with <IfModule mod_expires.c> and ends with the first </IfModule> you see after it, and make it look like this:

<IfModule mod_expires.c>

############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires

     ExpiresActive On
     ExpiresDefault "access plus 1 year"

</IfModule>

Color coding of code is added for readability and is not actually part of the code.


Magento Administration Tweaks

Merge CSS and JS

This particular tweak will reduce the number of HTTP requests on your eCommerce site. If you are using a Magento version prior to 1.4.x, the free extension Fooman_Speedster can be used, if you are running a later version of Magento follow this:

  1. Login to your administration area and go to - System > Configuration > Developer
  2. Under "JavaScript Settings", change "Merge JavaScript Files" to yes.
  3. Under "CSS Settings", change "Merge CSS Files" to yes.
  4. Finally you will want to clear your Magento cache.

 

Enabling Flat Catalog

The model Magento uses to store customer and product data results in longer than average SQL queries and more reads. Enabling the Flat Catalog option for Categories and Products will merge product data into one table, therefore improving performance.

  1. Login to your administration area and go to - System > Configuration > Catalog
  2. Under "Frontend", change "Use Flat Catalog Category" to yes.
  3. Under "Frontend", change "Use Flat Catalog Product" to yes - this is optional.
  4. Finally you will want to clear your Magento cache.

Database Maintenance Tips

One of the main issues with Magento sites running slowly, is a database that has become large and difficult to use for sending/retrieving data from.

Here are a few tips for reducing the size of your Magento database.

NOTE: Please be sure to generate a backup before performing any of the following changes.

Database Logs

There are several tables used by Magento for logging. While logging is very important regarding knowing what has and is going on with your store, the logs can become large very quickly, so regularly maintenance can be of great assistance.

Here are the tables for logging:

log_customer
log_visitor
log_visitor_info
log_url
log_url_info
log_quote
report_viewed_product_index
report_compared_product_index
report_event
catalog_compare_item

 

Database Log Cleaning using Magento Administration

  1. In Magento Administration go to System > Configuration
  2. In the left menu under Advanced click on System
  3. Under "Log Cleaning", change "Enable Log Cleaning" to YES and configure the Save Log for 14 days.
  4. Click "Save Config"

log.php Utility

Magento provides a shell utility that can be configured using Cron or run manually to clean the database logs.

Manually

Log into your account via SSH and cd to the Magento root directory thentype:

php -f shell/log.php clean

You can use the -days switch to specify how many days back to save

Cron

  1. You will want to login to cPanel
  2. Click on Cron Jobs

This is an example only:

php -f 
/home/yourcpanelusername/public_html/path/to/magento/shell/log.php

Note: The above line is on one line and may have been word-wrapped by the web browser. You may want to copy and paste to make sure everything is on one line.
 

Database Cleaning via phpMyAdmin

Using phpMyAdmin offers more flexibility and efficiency when working with databases.

  1. Login to cPanel and click on phpMyAdmin
  2. Click on the database associated with your Magento installation
  3. Now select these tables:
log_customer
log_quote
log_summary
log_summary_type
log_url
log_url_info
log_visitor
log_visitor_info
log_visitor_online
  1. Below the tables listed, click on the drop-down box "With Selected:" and select Empty
  2. You will get a confirmation screen, click Yes.

You will want to perform this database log cleaning on a regular basis. Utilizing the cron job option will ensure it is done without the need to perform any manual tasks. You will want to be sure you have properly setup this cron.

  • 0 gebruikers vonden dit artikel nuttig
Was dit antwoord nuttig?