Speed up Magento with simple config tweaks
At Ionata we’ve been using Magento for quite a while now and the more sites we added, the slower our server seemed to become. Magento is quite a big chunk of software and can take up a lot of resources. However after doing some research and carefully tweaking our server configurations, we were pretty amazed to find performance gains of several hundred percent only by changing some settings.
In this post you’ll find a summary of settings that can boost the speed and responsiveness of your Magento installation. Optimisation can be done for PHP, MySQL, Apache and Magento itself.
Optimising PHP
The bottleneck here is the memory limit for PHP scripts. Older PHP versions came with a fairly low memory limit of 8 or 16 Megabyte. Edit your php.ini file and look for the following line:
memory_limit = 8M
Try setting this to 128M if it is not already set. If you don’t have access to the php.ini (which is likely on shared hosting) you can also try setting the parameter from within a PHP file:
ini_set('memory_limit', '128M');
A third option is to change it from the .htaccess file in your Magento directory. Add the following line:
php_value memory_limit 128M
Optimising MySQL
Very big potential for speed gains offers MySQL. Since database applications like Magento often use the same SQL queries over and over again, MySQL offers a query cache that is set with the have_query_cache and query_cache_size parameters. The cache is disabled by default, but enabling can result in massive speed improvements. There is already an excellent article at Crucial Web Hosting about the importance of query caching and how to enable it, so I’ll skip the details here and recommend you check it out.
Optimising Apache
Magento offers an option to enable ZIP (Deflate) compression for Apache. You can imagine that a big part of a typical Magento page (as the user can see it) actually consists of text: HTML, CSS and Javascript. Text files offer excellent compression ratios, so it only makes sense to run Apache with compression enabled to reduce the amount of data that needs to be transferred to the user. You can enable it from Magento’s .htaccess file. Look for the following section:
<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>
Uncomment the important lines so 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>
Optimising Magento
Last but not least there is potential to improve Magento itself, by enabling the built-in caches. Under System > Cache Management you should make sure that all caches are enabled. Usually caches should be disabled completely during development, but on a production server it is essential to enable all of them. Server load would otherwise increase significantly.
Comments
awesome article, i just wish they didnt package the JS up like they have. for me it is the biggest problem.
Thanks for the link to our ‘Using MySQL Query Cache for Magento’ article – looks like there may have been a URL problem as we noted several 404 errors coming from your excellent article.
The correct URL to the full article on our blog is below.
http://www.crucialwebhost.com/blog/improving-magento-speed-performance-with-mysql-query-cache/
Cheers!
Strange. The link in my article works for me, but the one in your comment gives me a 404.
Yup, you are correct – we had an rewrite issue and you had the correct URL. We corrected the issue shortly after we spotted it thanks to your article. My mistake –
Thanks again and keep up the great work!
Cheers!
No worries :)
Cheers
Thanks for the tips Matthias! I also created an article about Magento performance: “101 ways to speed up your Magento e-commerce website” (http://blog.guidojansen.nl/2010/05/18/101-ways-to-speed-up-your-magento-e-commerce-website/). It contains tips on server level, Magento config level and templating level. I hope it helps you tweaking Magento a bit, let me know if you have additional tips!
We have developed a Magento page caching module that reduces page response times to lower than half a second. You can see our module working at zumiez.com and redmarblesteaks.com
Check us out at http://store.delorumcommerce.com
Hey …
Nice Tricks …..
Its increases site speed … thanks…..
Hi there,
Nice round up. Worth noting is that
SetOutputFilter DEFLATE
will cause problems with downloads if you are setting downloadable products. Using
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
instead will get around this
ps love the on / off switch