One of the drawbacks of Magento is currently its speed if default configuration is used. There are certain ways of making it run faster. The best one is to enable GZip compression by changing .htaccess file a little. You just need to uncomment part of the code. In my case, the speed increase was exactly 235%. Let’s start speeding up Magento!
Find the following lines in your Magento .htaccess file and replace them with the following code.
############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip
# Insert filter
SetOutputFilter DEFLATE
# 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
# enable resulting html compression
php_flag zlib.output_compression on




Wow, amazing how much this changes. It’s actually pretty fast now.
Thanks for the advice!
Cheerz, Casper.
You can also play with DeflateBufferSize and DeflateCompressionLevel settings. But don’t make DeflateCompressionLevel too high, though
Thanks Vladimir,
Can you please present the examples of such usage?
I did it this way (this is a part of <VirtualHost> declaration):
<IfModule mod_deflate.c>
DeflateBufferSize 32768
DeflateCompressionLevel 5
<Location />
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|tiff)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
</Location>
</IfModule>
Thank you
Hi!
is this valid for *any* webhosting?
thanks.
-andres
Hi Andrés,
Most of the things don’t always work on all hostings. For example, I’m sure Vladimir’s suggestion is ok, but that doesn’t work on mine.
Wow this works really well, thanks for the advice!
Amazing! Thank you!
my htaccess file already looks like that. i just d-loaded two days ago. am i missing something?
When I try this on Mosso clustered hosting I get a 500 Internal Server error
i just tried using magento, but it’s way slow. where can i get the .htaccess file? the one i got off my server only has 3 lines in it about “order deny, allow Deny from all”
this isn’t the right file is it?
Thanks, fortunately it did help making magento run three times faster
Made a huge difference unreal
What a difference far faster, i’m not 100% sure but this htaccess setup should work on any website!
AC-k3v, yes Magento v 1.1.6 has the coding in the htacess, however it is in a comment block and needs editing out.
It depend if Apache is 1.3 or 2.0. I have Apache 1.3 and i have to use mod_gzip setting in htaccess:
mod_gzip_on Yes
Someone posted a comment to my post (that refers to your solution) mentioning there’s another line of code that needs to be uncommented otherwise I don’t think these changes work.
############################################
## enable resulting html compression
php_flag zlib.output_compression on
Thanks man! Works Great!
Fantastic! – Good call on uncommenting the zlib flag, XPC.
Id didn’t work for me, should it start working as soon as you modify the .htaccess? Did I miss another step?
thanks so much!!!!! it truly works much more faster than before!
@Aldo
Yes, it should start when you modify .htaccess file. If it doesn’t work, there could be several reasons, probably related to server configuration. Also, take a look at the comment from XPC Design to see if it helps.
Many thanks.
thanks for the info Bilic…
is this compatible with magento-1.2.0.3, also?
GREAT JOB
……yes it works with 1.2.0.3
Can someone cut and paste their htaccess file? Mine keeps giving me a 500 Internal Server Error when I add Vladimr’s suggestions
@Mark:
Commenting this out solved the 500 here:
# Make sure proxies don’t deliver the wrong content
# Header append Vary User-Agent env=!dont-vary
Nice maybe I’ll start my own “fast” $20-$50 / month web hosting company with this, it improved my speed by at least 10,000% on a $3 / month web host….no joke
I did as the above instruction but no success. the site’s speed seems not changed anymore. I use magento 1.3.0
Great tip. Thanks!
didn’t help my site out.
Magento 1.3.2.1
hosted at Crucial Webhosting on a split-shared container.
Just did this on my dedicated linux vm @ GoDaddy and my time to first byte went from ~40sec to 1.5sec-6sec.
HUGE IMPROVEMENT!! THANK YOU!!
Worked fine for me thanks a lot
Very helpful,very good!
Nice one !! And thanks for your guidance.
Thank you for this nice and helpful article.
Pingback: Boost the performance of your magento installation | Magento News
way faster… it took several page loads to see the difference, but it is much better now. thanks!
i tried many examples. But couldn’t able to find the correct solution to make the magento site speedup.
Check my website at http://www.theplrmart.com which is running slowly.
can anyone kindly help me out in getting the site fast please
Regards
Venkat
Hi PLR Mart
I got exactly the same problem. Seems to stall during the initializiation.
Have you enable the profiler to see where it hangs in your case?
Regards
Fred
This works. thank you
I added this to my install, tried all the different uncomments, and I still receive a Internal Server Error (500). The only way I’ve been able to get this to go away is to uncomment
# enable resulting html compression
php_flag zlib.output_compression on
Which I’m sure is needed….
Any input??
This is a great site.. thanks for providing all these lovely hints and tips… this one reminded me that i forget to set compression on one of my sites. doh!
the other 2 big things that made a difference for me was the installation of xcache and adding /var/cache to tmpfs
doing a apache benchmark 3000 times on the site after adding xcache to 1.8 seconds a drop from 11.3ish
hope this helps
Thanks for the tutorial its made a big difference as far as I can tell. I would like to double test it via some type of website speed checker though just to be sure. Could any one recommend a good one?
I use this one
http://www.freespeedtest.com/
gives a general idea of speeds from different parts of the world. or if you are offering hosting you could look at http://magebenchmark.sonassi.com/
Thanks Andy for your help, cheers
Wow!!! I tested my sites speed at http://www.freespeedtest.com before I did the .htaccess update:
Before: 16.34 seconds
After: 2.27 seconds
Amazing thanks!!!
Wow! Magneto pages are now loading in less than a second! See http://www.itsournature.com/
Very helpful, i’m hosting site on godaddy Deluxe linux hosting.
Can someone take a look at my htaccess and tell me how to make the seed mods to it. everytime I try I get the 500 Internal Server error
Thanks
############################################
## uncomment these lines for CGI mode
## make sure to specify the correct cgi php binary file name
## it might be /cgi-bin/php-cgi
# Action php5-cgi /cgi-bin/php5-cgi
# AddHandler php5-cgi .php
############################################
## GoDaddy specific options
# Options -MultiViews
## you might also need to add this line to php.ini
## cgi.fix_pathinfo = 1
## if it still doesn’t work, rename php.ini to php5.ini
############################################
## this line is specific for 1and1 hosting
#AddType x-mapp-php5 .php
#AddHandler x-mapp-php5 .php
############################################
## default index file
DirectoryIndex index.php
## 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
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
############################################
## you can put here your magento root folder
## path relative to web root
#RewriteBase /magento/
############################################
## workaround for HTTP authorization
## in CGI environment
RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
############################################
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]
</IfModule>
############################################
## Prevent character encoding issues from server overrides
## If you still have problems, use the second line instead
# AddDefaultCharset Off
#AddDefaultCharset UTF-8
<IfModule mod_expires.c>
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
ExpiresDefault "access plus 1 year"
</IfModule>
############################################
## By default allow all access
Order allow,deny
Allow from all
############################################
## If running in cluster environment, uncomment this
## http://developer.yahoo.com/performance/rules.html#etags
#FileETag none
please alabore what lines should be changed in htaccess file