Boost the speed of your Magento

Featured Image

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

118
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Tomislav is an owner and CEO of Inchoo. Enjoys traveling, traditional cuisine (from most cultures), good wine and strong rakija.

Other posts from this author

Discussion 118 Comments

1 2 3
Add Comment
  1. Wow, amazing how much this changes. It’s actually pretty fast now.

    Thanks for the advice!

    Cheerz, Casper.

  2. You can also play with DeflateBufferSize and DeflateCompressionLevel settings. But don’t make DeflateCompressionLevel too high, though

  3. Tomislav Bilic

    Thanks Vladimir,

    Can you please present the examples of such usage?

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

  5. Tomislav Bilic

    Thank you :)

  6. Hi!
    is this valid for *any* webhosting?

    thanks.
    -andres

  7. Tomislav Bilic

    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.

  8. Wow this works really well, thanks for the advice!

  9. Amazing! Thank you!

  10. AC-k3v

    my htaccess file already looks like that. i just d-loaded two days ago. am i missing something?

  11. When I try this on Mosso clustered hosting I get a 500 Internal Server error

  12. jc

    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?

  13. Thanks, fortunately it did help making magento run three times faster :)

  14. Made a huge difference unreal

  15. Colin

    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.

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

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

  18. Thanks man! Works Great!

  19. Ben

    Fantastic! – Good call on uncommenting the zlib flag, XPC.

  20. ~aldo

    Id didn’t work for me, should it start working as soon as you modify the .htaccess? Did I miss another step?

  21. ana

    thanks so much!!!!! it truly works much more faster than before!

  22. @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.

  23. Stavros

    thanks for the info Bilic…

    is this compatible with magento-1.2.0.3, also?

  24. GREAT JOB
    ……yes it works with 1.2.0.3

  25. Can someone cut and paste their htaccess file? Mine keeps giving me a 500 Internal Server Error when I add Vladimr’s suggestions

  26. cradossk

    @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

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

  28. Neo

    I did as the above instruction but no success. the site’s speed seems not changed anymore. I use magento 1.3.0

  29. Great tip. Thanks!

  30. davidd

    didn’t help my site out.
    Magento 1.3.2.1
    hosted at Crucial Webhosting on a split-shared container.

  31. Major

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

  32. Worked fine for me thanks a lot

  33. dueto

    Very helpful,very good!

  34. jayu

    Nice one !! And thanks for your guidance.

  35. Thank you for this nice and helpful article.

  36. Pingback: Boost the performance of your magento installation | Magento News

  37. way faster… it took several page loads to see the difference, but it is much better now. thanks!

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

  39. Fred

    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

  40. This works. thank you

  41. Cole

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

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

  43. 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?

  44. 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/

  45. Thanks Andy for your help, cheers

  46. 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!!!

  47. Wow! Magneto pages are now loading in less than a second! See http://www.itsournature.com/

  48. yeexi

    Very helpful, i’m hosting site on godaddy Deluxe linux hosting.

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

  50. please alabore what lines should be changed in htaccess file

1 2 3

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top