20 Ways to Speed Up Magento

Thought I would post a ‘How To Speed up Magento’ Guide based on what I have found out. And maybe others can chip in afterwards with their top tips, and we can turn this into a one-stop thread to getting Magento installs working nice and fast smile

1/ Install Fooman Speedster

This one made a massive difference to page loads for the first site I am testing.


2/ Enable Gzip Compression in .htaccess


To do this, uncomment this part in the .htacess: (Line 52)

#php_flag zlib.output_compression on

(ie Remove the # save and reupload)

(Next 4 are from – http://www.magentocommerce.com/blog/comments/performance-is-key-notes-on-magentos-performance/)

3/ Install APC or Xcache

APC – http://pecl.php.net/package/APC

Xcache – http://xcache.lighttpd.net/

Looking at benchmarks and folks comments, it seems to be a toss of coin which one to go for.

I will probably go for APC on balance.

Will be asking my host to install this.

Ok. My host installed it. And further to Discovery posting below, thought I would add that in here to the main body. Discovery pointed out that thread here had extra tips once APC had been installed:http://www.magentocommerce.com/boards/viewthread/9882/

Essentially, after APC has been installed, you locate the local.xml file in the install. (Mine was here – /home/yoursitename/public_html/app/etc/local.xml

You then add the following code to just below:




I have to say that I actually have installed APC, and then tried this, but that it actually slowed down my server. Response times went up from about 2 seconds to 3 seconds.

Your mileage may however vary, so give it a go grin

Edit to My Edit….  wink Turns out I didn’t have APC installed properly. Thought it was odd that I had no speed improvements when everyone else seemed to, so I went hunting for the reason.

Found this thread here on php.net


Point this part out to your host:

Once you have a running server, you should copy the apc.php script that comes with the extension to somewhere in your docroot and load it up in your browser. It provides you with a detailed look at what is happening in your cache. If you have GD enabled in PHP, it will even have pretty graphs.

Then you can check out http://www.yourdomain.com/apc.php and decide whether its working.

(If you compare the one on your own server to this one on the PHP server:


then it becomes clearer whether it is working correctly)

4/ “Make sure your Apache configuration has KeepAlives enabled. KeepAlives are a trick where multiple HTTP requests can be funneled through a single TCP connection. Since the setup of each TCP connection incurs additional time, this can significantly reduce the time it takes to download all the files (HTML, JavaScript, images) for a website.”

No idea what this is. And there is no further mention of it anywhere. So I will ask my host to enable it.  Would be good to have some more info on this, if anyone knows what it is?

5/”Modify the configuration for your MySQL server to take better advantage of your server’s RAM. Most Linux distributions provide a conservative MySQL package out of the box to ensure it will run on a wide array of hardware configurations. If you have ample RAM (eg, 1gb or more), then you may want to try tweaking the configuration. An example my.cnf is below, though you will want to consult the MySQL documentation for a complete list of configuration directives and recommended settings.”

They have a list of settings there for my.cnf as follows:

key_buffer = 512M
max_allowed_packet = 64M
table_cache = 512
sort_buffer_size = 4m
read_buffer_size = 4m
read_rnd_buffer_size = 2m
myisam_sort_buffer_size = 64m
tmp_table_size = 128m
query_cache_size = 96m
query_cache_type = 1
thread_cache_size = 8
max_connections = 400
wait_timeout = 300

Again, get your host to do it, (which is what I will be doing smile) or figure it out.

6/ “Use a memory-based filesystem for Magento’s var directory. Magento makes extensive use of file-based storage for caching and session storage. The slowest component in a server is the hard drive, so if you use a memory-based filesystem such as tmpfs, you can save all those extra disk IO cycles by storing these temporary files in memory instead of storing them on your slow hard drive.”

Ok. Rather unhelpfully, there is no mention anywhere of how to do this.

So, if someone could post a step by step on this, then that would be useful.

7/ This thread here – http://www.magentocommerce.com/boards/viewthread/5366/P60/ – Includes a post from a Server Admin at Rackspace who had experience optimizing for Magento

The two that jumped out at me were:

a/ First off, I made some changes to your system, I increased the APC.shm.size to 128 This will allow more data to be cached by apc, in theory it’ll store more data.

(This sounds like it is linked to APC above – So maybe install APC first before doing this smile)

8/ From thread above:

“I also made some changes to the vhost.conf file for the shop site, historically disabling open_basedir allows magento to work slightly better.”

No idea what this is. Any guru’s care to comment? A step by step would be useful from someone if you know how to do it.

9/ There is a comment added to this thread that seems to add another piece of the jigsaw:


As many people, after having been wondered by Magento look and features, I’d been frustrated by the loading time.
I then have decided to make some server tuning to improve page loading performances.
I’ve first installed xcache, used tmpfs for cached page (mysql query cache was already in process).
Loading time, for all the demo store pages, has been clearly cut .

Having full access to apache configuration files, I’ve removed .htaccess files rules from directories to virtualhost configuration directives.
This change has improved loading speed as much as xcache installation. Further more, it has divided loading time by 2 for the smallest server I’ve used for test.


In this post Francoise is claiming that doing this:

“I’ve removed .htaccess files rules from directories to virtualhost configuration directives.”

Doubled the speed of the loading times!

Yet I can find no other information anywhere about what this is, or how to do it.

Can someone who knows what Francois is talking about please comment and/or post a how to guide as to how to do this.

10/ Clustering

Details here – http://www.magentocommerce.com/blog/comments/performance-is-key-notes-on-magentos-performance/

This comes under the ‘get more servers’, ‘better equipment’ banner; which is of course the obvious way to improve speed grin

And also this one…

11/ Optimizing MySQL Database

After all products and categories have been imported into the MySQL Database then go into webhost manager and select PhpMyAdmin at the bottom. (I have cpanel on my panel

Select the relevant database and first repair all the tables, and then optimise them.


Found some new ones wink

12/ Magento Caching.

Goto Magento Admin -> System -> Cache Management
– Tick the following items:
— Configuration
— Layouts
— Block HTML output
— Translations

-Untick the following items: (if ticked they seem to have a negative impact atm)
— Collections Data
— EAV types and attributes
— Web Services Configuration

Found Here – http://www.magentocommerce.com/boards/viewthread/24595

Further Explanation Here: http://www.magentocommerce.com/boards/viewthread/12055/

I tried this out and the juries out from my end whether it made much difference. Maybe worth a try though to test out on your own install.

13/ Remove Home Page Elements

Goto Magento Admin -> CMS -> Manage Pages -> Home -> Custom Design
– The “Layout Update XML” box is pre-populated with functions and calls, all of which can be removed without any apparent problems, according to a number of forums comments.

Found Here – http://www.magentocommerce.com/boards/viewthread/24595

14/ Compressing CSS Files

Found Here – http://www.magentocommerce.com/boards/viewthread/24595 (as described by aquiss)

Introduce a new Apache AddHandler to compress CSS files on the fly. I came across this technique eleswhere on the Internet, but my site pages are now flying as a result.

– Create a file called “gzip-css.php” and add/save the following into it:

<?phpob_start ("ob_gzhandler");header("Content-type: text/css; charset: UTF-8");header("Cache-Control: must-revalidate");$offset = 60 * 60 ;$ExpStr = "Expires: " .gmdate("D, d M Y H:i:s",time() + $offset) . " GMT";header($ExpStr);?>

– Create a file called “.htaccess” and add/save the following into it:

AddHandler application/x-httpd-php .cssphp_value auto_prepend_file gzip-css.php

– Locate your template CSS directory and upload both files that you created to it.

cd skin/frontend/default/YOUR_TEMPLATE/css/

PS I actually tried this (the post above has someone saying that there style sheets didn’t work afterwards), and it worked fine for me.

One suggested change for those it didn’t work for in that thread was to change:

AddHandler application/x-httpd-php .css to AddHandler application/x-httpd-php5 .css

However, as I said, the original version worked fine for me.

15/ Enable GZip Compression in the .htaccess (Part 2)

By deafult the .htaccess has this:

############################################## 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</IfModule>

Change to:

############################################## enable apache served files compression## http://developer.yahoo.com/performance/rules.html#gzip# Insert filterSetOutputFilter DEFLATE# Netscape 4.x has some problems...BrowserMatch ^Mozilla/4 gzip-only-text/html# Netscape 4.06-4.08 have some more problemsBrowserMatch ^Mozilla/4.0[678] no-gzip# MSIE masquerades as Netscape, but it is fineBrowserMatch bMSIE !no-gzip !gzip-only-text/html# Don't compress imagesSetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary# Make sure proxies don't deliver the wrong contentHeader append Vary User-Agent env=!dont-vary</IfModule>

Source: http://www.xpcdesign.com/2008/09/speed-up-magento-by-235/


With regard to 15/ this post here:


Tipped me off that mod_deflate has to be loaded in Apache for this to work:

Make i am wrong,

But the mod_deflate has to be loaded in apache, before it has an effect in htaccess

Remove the # from

#LoadModule deflate_module modules/mod_deflate.so

and restart apache.


Most guides I have found on the net as to how to do this give the impression that you need Apache2? Not sure. I am checking with my webhost, and will update this when I know.

eg http://streetsmartingit.blogspot.com/2007/11/how-to-compileinstall-moddeflate-into.html

I tried adding the line:

LoadModule deflate_module modules/mod_deflate.so

To the usr/local/apache/conf/httpd.conf file. and then re-compiling Apche (you do this in WHM – If you have a cpanel install – on the far left where it says ‘Restart services’ – You just click on HTTP Server (Apache)) – But mine failed. So I had to remove the line, upload it again (ie the same as before) and it worked fine.

The line didn’t seem to be in the httpd.conf file anywhere though. Anyhow, will update when I know grin

Update: My host has got back to me and mod_deflate does indeed require Apache2 to run.

Beyond my skills to install this, but my hosts are excellent, and have made no problem of doing it for me.

— Hmmm, Just looking at load times. They were previously 1.5 to 2 seconds; and after changing to apache2 they are 1.5 to 3 seconds. I reckon its added at least half a second (and often a second) to load times. So, on my server at least, this may be a duffer and I will be rolling back to Apache 1.

Ok. Decided to try Apache 2.2.

So, I have now tried Apache 1.3 (no mod drflate), Apache 2.0.63 (with and without mod_deflate) and without mod_deflate.

Honestly, I would have to say that 1.3 without mod_deflate was the quickest. Apache 2.0.63 with mod_deflate the slowest.

I have settled on Apache without mod_deflate, because whilst I think it is actually marginally slower then 1.3 (as measured by yslow – http://developer.yahoo.com/yslow/) it is at least being updated with new features. And the speed difference is not large in my view.

16/ Change realpath_cache_size in php.ini

Just found this post here: http://www.magentocommerce.com/boards/viewthread/8650/P0/

This has a tip in it to add the following to your php.ini file (mind is found here – /usr/local/lib if you are trying to locate it :-))

realpath_cache_size=1M (careful, this is per apache process)realpath_cache_ttl=86400 (ok for production site)

I tried this, and I have to say that the site definitely feels faster. The yslow numbers are not much different, but I would say that it because it doesn’t seem to have speeded up the loading up of the images on the page (from what I can see). The actual html page and text are definitely appearing faster.

Note: Regarding the replace_recursive.php file that he also discuesses in that thread… I had a look at my own install (Located here – /home/cpanelsitename/public_html/lib/Zend), and it seems that it is already in there, so I assume that this is now part of the core magento install

17/ Put data.php and exception.php in the cache


There is an interesting aside in the above thread by graes0 – http://www.magentocommerce.com/boards/member/13236/:

I was wondering if somebody know how to put the files data.php and exception.php in the cache which would increase the performance a lot.

Not sure whether or not this is a clue to someone that could increase performance?

Personally, I have no idea what he is taking about, so you will have to make up your own mind 🙂 If you do know. And it makes sense, then post how to do it below.

18/ Changes to MySQL Configuration

Ok. Right. My server flipped out this morning and had some speed problems after Apache crashed, so I had to get in touch with my host (who have been excellent) about speeding the site back up.

Two things that they recommended: (This is my server guys words)

“changing the temporary directory for eaccelerator to /home/eaccelerator because it looked like it may have been having space issues on /tmp.”

And the following changes to the MySql Configuration:


“Increase max_heap_table_size and tmp_table_size (I would probably try doubling each to 32M and 256M, respectively) Doubling the table_cache to 2048 Tables Enabling log-queries-not-using-indexes so we can see if there are performance gains to be had there and increasing the query_cache size to 256M

This may decrease the time spent waiting for the mysql requests, but at the cost of more memory.”

19/ Change from Apache to Litespeed Web Servers

Several posts on here make reference to changing from Apache to Litespeed as a way of improving the speed of Magento.

(Details on Litespeed here – http://www.litespeedtech.com/products/webserver/overview/)


Evan Brassart has done a good post on his blog explaining how to compile Litespeed for use with Magento –


20/ New for Version 1.3… 

Enable Flat Categories and Flat Products


# To enable one or both first go to your admin panel and navigate to System->Cache Management. Under Catalog click on the Rebuild button next to Rebuild Flat Catalog Category or Product.
# Navigate to System->Configuration click on Catalog and select the Frontend tab. Choose Yes next to the appropriate selection of either Use Flat Catalog Category or Product.



Was this blog post helpful for you?

Support my blog and donate!

My blog is open to the public and will always be freely available. With your donation, we can help others learn, together.

Donate in Bitcoin: