How to Optimize Magento
Magento is a popular and powerful eCommerce platform recognized for its robust features and high level of customization right from the initial installation. To help you optimize Magento, consider the following recommendations for improving your overall setup.
Remember that Magento is resource-intensive. If you begin experiencing performance slowdowns or resource limitations on a shared hosting plan, it’s best to upgrade to a dedicated server. VPS hosting may also fall short for high-traffic Magento stores, as it can sometimes provide fewer resources compared to shared hosting environments.
Changes to .htaccess
Enable Output Compression
Inside your Magento .htaccess file, locate the block that begins with <IfModule mod_deflate.c> and ends with </IfModule>.
This block controls Apache’s mod_deflate module, which compresses text, CSS, and JavaScript files. Uncomment (remove the #) the necessary lines so the section appears 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 more issues
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape but works fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Exclude images from compression
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Prevent proxies from serving the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
Enable Expires Headers
First-time visitors generate multiple HTTP requests. By enabling the “Expires” header, repeat visits use cached files, reducing unnecessary requests and improving page load times.
Find the section of your .htaccess file that begins with <IfModule mod_expires.c> and ends with the first </IfModule> after it, then update it to match the following:
<IfModule mod_expires.c>
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
ExpiresActive On
ExpiresDefault "access plus 1 year"
</IfModule>
Note: Color highlights shown above are for readability only and are not part of the actual code.
Magento Administration Tweaks
Merge CSS and JS
This adjustment helps reduce the total number of HTTP requests made by your Magento store. For Magento versions earlier than 1.4.x, you can use the free extension Fooman_Speedster. For later versions, follow these steps:
- Log in to the Admin Panel, then go to System > Configuration > Developer.
- Under “JavaScript Settings,” set “Merge JavaScript Files” to Yes.
- Under “CSS Settings,” set “Merge CSS Files” to Yes.
- Clear the Magento cache.
Enabling Flat Catalog
Magento’s EAV (Entity Attribute Value) database model can result in long and complex SQL queries. Enabling the Flat Catalog consolidates product data into a single table, improving speed and performance.
- Go to System > Configuration > Catalog.
- Under “Frontend,” set “Use Flat Catalog Category” to Yes.
- Optionally set “Use Flat Catalog Product” to Yes.
- Clear the Magento cache.
Database Maintenance Tips
A common cause of slow Magento performance is an oversized database, which makes queries slower and less efficient.
Below are suggestions to clean and reduce your Magento database size.
Database Logs
Magento stores logs in several tables. While logging is useful, these tables can grow very large and require maintenance.
Common log tables include:
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
- In the Admin Panel, go to System > Configuration.
- Under Advanced, click on System.
- Enable “Log Cleaning” and set the retention to 14 days.
- Click “Save Config.”
log.php Utility
Magento includes a shell script that can be run manually or via cron to purge log tables.
Manual Cleaning
Access your site through SSH, navigate to the Magento root directory, and run:
php -f shell/log.php clean
You can also specify a time range using the -days flag.
Using Cron
- Log in to cPanel.
- Select Cron Jobs.
Example command:
php -f
/home/yourcpanelusername/public_html/path/to/magento/shell/log.php
Note: The example above is a single-line command; your browser may wrap it automatically.
Database Cleaning via phpMyAdmin
phpMyAdmin offers a convenient way to remove log data directly.
- Log in to cPanel and open phpMyAdmin.
- Select the database used by your Magento installation.
- Select the following tables:
log_customer
log_quote
log_summary
log_summary_type
log_url
log_url_info
log_visitor
log_visitor_info
log_visitor_online
- Under “With Selected,” choose Empty.
- Confirm the action by clicking Yes.
Performing regular log cleaning helps maintain performance. Setting up a cron job ensures the process runs automatically without manual intervention.
Summary
This guide outlines several methods for optimizing Magento, including .htaccess enhancements for compression and caching, administrative settings to merge assets and enable Flat Catalog mode, and essential database maintenance practices. Using built-in tools, shell commands, or phpMyAdmin, you can manage logs effectively and ensure your Magento installation continues performing efficiently.
If you need further assistance, feel free to contact us via Chat or Phone:
- Chat Support - While on our website, you should see a CHAT bubble in the bottom right-hand corner of the page. Click anywhere on the bubble to begin a chat session.
- Phone Support -
- US: 888-401-4678
- International: +1 801-765-9400
You may also refer to our Knowledge Base articles to help answer common questions and guide you through various setup, configuration, and troubleshooting steps.