Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 7
Methods To Speed Up Magento - A Guide To Making Magento Faster
 
Stuarts
Member
 
Total Posts:  66
Joined:  2009-03-16
 

Methods To Speed Up Magento

Hi Guys,

Ok. Figuring out how to get this puppy purring over the last few days.

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.

http://www.magentocommerce.com/extension/457/fooman-speedster

2/ Enable Gzip Compression in .htaccess

http://www.magentocommerce.com/boards/viewthread/7100/

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:

<global>

<cache>
<
backend>apc</backend>
<
prefix>alphanumeric</prefix>
</
cache>

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

http://uk3.php.net/manual/en/apc.configuration.php

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:

http://www.php.net/~rasmus/apc.php

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)

(Continued in next post because I ran out of characters… grin)

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stuarts
Member
 
Total Posts:  66
Joined:  2009-03-16
 

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:

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

“Hi,
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.

Francois
http://www.azolia.fr”


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.

http://www.magentocommerce.com/boards/viewthread/10152/

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.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stuarts
Member
 
Total Posts:  66
Joined:  2009-03-16
 

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:

<?php
ob_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 .css
php_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 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>
Source: http://www.xpcdesign.com/2008/09/speed-up-magento-by-235/

Right.

With regard to 15/ this post here:

http://www.magentocommerce.com/boards/viewthread/12055/P0/

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.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stuarts
Member
 
Total Posts:  66
Joined:  2009-03-16
 

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 2.2.1.2 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 2.2.1.2 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 (carefulthis 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

http://www.magentocommerce.com/boards/viewthread/8650/P0/

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/)

http://www.magentocommerce.com/boards/viewthread/31454/

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

http://www.evanbrassart.com/category/development/magento-commerce/

20/ New for Version 1.3…

Enable Flat Categories and Flat Products

http://www.magentocommerce.com/blog/comments/magento-version-130-is-now-available/

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


Ok. There you go guys.

20 Ways that I have found so far to potentially speed up a Magento install.

Please post any new ways that you find below so that we can turn this into a useful repository of tips for everyone grin

There is more power in sharing, so share any speed up tips you have here grin


Stuart

 
Magento Community Magento Community
Magento Community
Magento Community
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

1) That extension breaks things, besides it just compresses files differently to how they would be compressed anyhows. You can delete the comments from your js and css to optimise it all by yourself and let the computer compress/cache as per normal.

3) APC. You also need to read this ere thread:

http://www.magentocommerce.com/boards/viewthread/9882/

That’s how to do the APC thing.

4) You probably have keepalives already. Put a file with <?php phpinfo(); ?> in it, save to /var/www/html/phpinfo.php then call http://www.host.com/phpinfo.php and see what you get. Keepalives will probably be in there somewhere.

6) tmpfs - see http://www.magentocommerce.com/boards/viewthread/9037/

When you have tmpfs working you can do du -sm /var/www/html/var/* to see what space is actually used. If you need to cut it down then you can by re-doing the tmpfs drive mount to be - say - 32M. Or you can set a drive up on tmpfs and check it later with df.
Also remember to add to /ect/fstab:

tmpfs /var/www/html/var/cache tmpfs rw,size=64m 0 0

That conveniently mounts the drive at boot, greedy 64Mb size, so you don’t have to forget grin

9) Putting the htaccess stuff in the main httpd.conf is a huge tip - thanks for that. Mine is vastly quicker now, My demo store furniture page loads in less than two seconds, Zolof T-shirt in 3.3. I was aiming for 4 seconds, I can live with 3…

With the htaccess out the way and the directives in a .conf include file you get a couple of warnings - not everything in there was that good and since it gets loaded every time you have to wonder. A typical message:  [warn] module php5_module is already loaded, skipping - it is better if that gets warned of once, not every time a file is accessed…

Not on the list…
-------------------

Memcache. Memcache is for the hardcore. It is documented in http://www.magentocommerce.com/boards/viewthread/9037/ and you may need tips from http://alexle.net/archives/275 to get you up and running. To run it on the loopback:

memcached -d -m 128 -l 127.0.0.1 -p 11211 -u nobody

Starting memcached at boot would be nice. There are some instructions somewhere on the interwebs:

http://www.vbseo.com/blogs/danny-bembibre/daemon-scripts-memcached-44/

Then /sbin/chkconfig memcached-init on

I am still testing that one, I think it kicks in on mega usage, i.e. when the server gets ‘slashdotted’.

Also, what it is about can be read here:
http://code.google.com/p/memcached/wiki/TutorialCachingStory

A big tip is to not have a hosting company… A shared server setup has the db fs and www servers on different machines that work no better than blu-tak and string.

Go for a virtual server at the minimum, something you can properly log onto. Never bother with anything more than a blog on a shared hosting setup. The pain is not worth it. Same goes for anything Windows… Also you should be command prompt all the way, not CPanel.

Despite the 4-5 hours compiling-searching fro rpms-installing and testing my SOAP API is only running 20% quicker than it was earlier.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

Also remembered smush-it - an online tool to compress your images down. It does it losslessly, taking header info out, suggesting pngs not gifs etc.

 
Magento Community Magento Community
Magento Community
Magento Community
 
FOOMAN
Guru
 
Avatar
Total Posts:  669
Joined:  2007-12-13
Auckland, New Zealand
 

Thanks for mentioning us.

@Discovery can you message me what breaks on your set up

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stuarts
Member
 
Total Posts:  66
Joined:  2009-03-16
 

9) Putting the htaccess stuff in the main httpd.conf is a huge tip - thanks for that. Mine is vastly quicker now, My demo store furniture page loads in less than two seconds, Zolof T-shirt in 3.3. I was aiming for 4 seconds, I can live with 3…

With the htaccess out the way and the directives in a .conf include file you get a couple of warnings - not everything in there was that good and since it gets loaded every time you have to wonder. A typical message:  [warn] module php5_module is already loaded, skipping - it is better if that gets warned of once, not every time a file is accessed…

Discovery, (or anyone else who knows) - Can you explain exactly what you did with this as a step by step?

I know that I put the tip in grin

That’s because I could clearly see that it had increased someones performance with Magento.  But I still didn’t really understand what Francoise had actually done, and I didn’t find mention of it anywhere else on here.

Now that two people have tried it and got such dramatic results, it REALLY makes me want to give it a go grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
azolia
Jr. Member
 
Total Posts:  5
Joined:  2008-09-25
 

Hi ,

As ‘discovery’ has experimented it, apache server is faster when .htaccess files are disallowed.
Consequently, Magento shop is responding faster too.
A french user, ryu007, wrote me months ago, that he has successfully speeded up his magento shop doing this.
Here is the explanation (see Apache tutorial) :

In general, you should never use .htaccess files unless you don’t have access to the main server configuration file. There is, for example, a prevailing misconception that user authentication should always be done in .htaccess files. This is simply not the case. You can put user authentication configurations in the main server configuration, and this is, in fact, the preferred way to do things.

.htaccess files should be used in a case where the content providers need to make configuration changes to the server on a per-directory basis, but do not have root access on the server system. In the event that the server administrator is not willing to make frequent configuration changes, it might be desirable to permit individual users to make these changes in .htaccess files for themselves. This is particularly true, for example, in cases where ISPs are hosting multiple user sites on a single machine, and want their users to be able to alter their configuration.

However, in general, use of .htaccess files should be avoided when possible. Any configuration that you would consider putting in a .htaccess file, can just as effectively be made in a <Directory> section in your main server configuration file.

There are two main reasons to avoid the use of .htaccess files.

The first of these is performance. When AllowOverride is set to allow the use of .htaccess files, Apache will look in every directory for .htaccess files. Thus, permitting .htaccess files causes a performance hit, whether or not you actually even use them! Also, the .htaccess file is loaded every time a document is requested.

Further note that Apache must look for .htaccess files in all higher-level directories, in order to have a full complement of directives that it must apply.

Most of Web applications sources available for download are including .htaccess files. This way, they can be hosted everywhere (if there is no special directive in those files).
If you’ve bought or hired a dedicated server, you should rewrite .htaccess directives in a main apache configuration file.

Here is an example of what could be VirtualHost directives for a Magento shop :

NameVirtualHost xx.12.84.18:80
<VirtualHost xx.12.84.18:80>
 
 
ServerName magento.speedy.abc
 DocumentRoot 
/var/www/magento

 
<Directory /var/www/magento>
  
Order allow,deny
  Allow from all
  DirectoryIndex index
.php
  AllowOverride None
  Options 
+FollowSymLinks
  AddDefaultCharset Off
  
  php_value memory_limit 64M
  php_value max_execution_time 300
  php_flag magic_quotes_gpc off
  php_flag session
.auto_start off
  php_flag suhosin
.session.cryptua off
  php_flag zend
.ze1_compatibility_mode Off
  php_flag zlib
.output_compression on
  
  RewriteEngine on
  RewriteBase 
/
  
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteCond 
%{REQUEST_URI} !^/(media|skin|js)/
  
RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond 
%{REQUEST_FILENAME} !-d
  RewriteCond 
%{REQUEST_FILENAME} !-l
  RewriteRule 
.* index.php [L]
  
  
<IfModule mod_security.c>
   
SecFilterEngine Off
   SecFilterScanPOST Off
  
</IfModule>
    
  <
IfModule mod_expires.c>
   
ExpiresDefault "access plus 1 year"
  
</IfModule>
 </
Directory>
 
 <
Directory /var/www/magento/lib >
    <
IfModule mod_deflate.c>
       
RemoveOutputFilter DEFLATE
      RemoveOutputFilter GZIP
    
</IfModule>
 </
Directory>
 
 <
Directory /var/www/magento/var >
   <
Files config.xml>
     
Deny from all
   
</Files>
 </
Directory>

</
VirtualHost>

The limitation is that you should be apache administrator (root on a dedicated server) to do that.
It’s impossible if you are running Magento on a shared hosting server.

Francois
http://www.azolia.fr

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stuarts
Member
 
Total Posts:  66
Joined:  2009-03-16
 

Ok. Right. Figured it out grin

This works…

This is a Step By Step to Tip 9

Removing .htaccess file rules from directories and putting them in httpd.conf

At Your own risk…
For the brave…
Oh Whatever. Just know that servers can, and do explode when you mess with them grin
In all seriousness, backup httpd.conf etc BEFORE you mess with it. In that way its easy to revert back if you mess this up (as I did a couple of times before figuring out what worked)

1/ Find the location of your httpd.conf file

If you look around the web then most places say it lives here:

/etc/httpd/conf/httpd.conf

However, in my own servers case it lives here:

/usr/local/apache/conf/http.conf

So you will have to hunt around and figure out where it is.

2/ Once you have that then download it to your computer and open up in notepad (I just did this using ftp, but there is probably a better way to do it with ssh)

3/ If you scroll through it you will see that it contains all the details of your different sites on your server, as well as different stuff that the script is automatically calling at the beginning.

You will ‘know’ which ones are which, because as you scroll through you will see something along the lines of:

<VirtualHost 42.12.238.79:80>
    
ServerName mydomain.com
    ServerAlias www
.mydomain.com

etc etc

To put this tip into operation scroll down to the site where the magento install is:

You will see two lines below it:

# To customize this VirtualHost use an include file at the following location
    # Include "/usr/local/apache/conf/userdata/std/2/yourcpanelname/mydomain.com/*.conf"

(Naturally the exact locations are going to depend on your installations, so the exact path will probably be different in your httpd.conf - But you get the idea)

Change that to: (ie uncomment it by removing the # and create a name for the new .conf we are going to create)

# To customize this VirtualHost use an include file at the following location
Include "/usr/local/apache/conf/userdata/std/2/yourcpanelname/mydomain.com/myhtaccess.conf"

4/ Save that file (Note - make sure to save it as httpd.conf and not anything dumb like .txt)

5/ Open up a blank new notepad and paste in the code that Francois rather handily provided as a starting point (you are going to want to put in stuff from your own .htaccess).


NameVirtualHost xx.12.84.18:80
<VirtualHost xx.12.84.18:80>
 
 
ServerName magento.speedy.abc
 DocumentRoot 
/var/www/magento

 
<Directory /var/www/magento>
  
Order allow,deny
  Allow from all
  DirectoryIndex index
.php
  AllowOverride None
  Options 
+FollowSymLinks
  AddDefaultCharset Off
  
  php_value memory_limit 64M
  php_value max_execution_time 300
  php_flag magic_quotes_gpc off
  php_flag session
.auto_start off
  php_flag suhosin
.session.cryptua off
  php_flag zend
.ze1_compatibility_mode Off
  php_flag zlib
.output_compression on
  
  RewriteEngine on
  RewriteBase 
/
  
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteCond 
%{REQUEST_URI} !^/(media|skin|js)/
  
RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond 
%{REQUEST_FILENAME} !-d
  RewriteCond 
%{REQUEST_FILENAME} !-l
  RewriteRule 
.* index.php [L]
  
  
<IfModule mod_security.c>
   
SecFilterEngine Off
   SecFilterScanPOST Off
  
</IfModule>
    
  <
IfModule mod_expires.c>
   
ExpiresDefault "access plus 1 year"
  
</IfModule>
 </
Directory>
 
 <
Directory /var/www/magento/lib >
    <
IfModule mod_deflate.c>
       
RemoveOutputFilter DEFLATE
      RemoveOutputFilter GZIP
    
</IfModule>
 </
Directory>
 
 <
Directory /var/www/magento/var >
   <
Files config.xml>
     
Deny from all
   
</Files>
 </
Directory>

</
VirtualHost>


I have to change Francois file up a bit because I want to include all the stuff that is currently in my .htaccess, and put in in there.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stuarts
Member
 
Total Posts:  66
Joined:  2009-03-16
 

Here is my original .htaccess so you can see what this is about.

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

<IfModule mod_php5.c>

############################################
## adjust memory limit

#    php_value memory_limit 64M
    
php_value memory_limit 128M
    php_value max_execution_time 18000

############################################
## disable magic quotes for php request vars

    
php_flag magic_quotes_gpc off

############################################
## disable automatic session start
## before autoload was initialized

    
php_flag session.auto_start off

############################################
## enable resulting html compression

    
php_flag zlib.output_compression on

###########################################
# disable user agent verification to not break multiple image upload

    
php_flag suhosin.session.cryptua off
    
###########################################
# turn off compatibility with PHP4 when dealing with objects
    
    
php_flag zend.ze1_compatibility_mode Off

</IfModule>

<
IfModule mod_security.c>
###########################################
# disable POST processing to not break multiple image upload

    
SecFilterEngine Off
    SecFilterScanPOST Off
</IfModule>

<
IfModule mod_deflate.c>

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

<
IfModule mod_ssl.c>

############################################
## make HTTPS env vars available for CGI mode

    
SSLOptions StdEnvVars

</IfModule>

<
IfModule mod_rewrite.c>

############################################
## enable rewrites

    
Options +FollowSymLinks
    RewriteEngine on

############################################
## you can put here your magento root folder
## path relative to web root

    
RewriteBase /

############################################
## workaround for HTTP authorization
## in CGI environment

    
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
## FOOMAN SPEEDSTER - EXTENSION    

############################################
## Compress, Combine and Cache Javascript/CSS
RewriteRule ^(index.php/)?minify/([^/]+)(/.*.(js|css))$ lib/minify/m.php?f=$3&d;=$2    

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

Ok. So I am now going to transcibe those elements in my .htaccess (that include the changes above eg Fooman Speedster etc) and using Francois structure as a template.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stuarts
Member
 
Total Posts:  66
Joined:  2009-03-16
 

( Directory will be the same as DocumentRoot eg /home/yourcpanelname/public_html)

I end up with the following:


<Directory /home/mydomain/public_html>
  
Order allow,deny
  Allow from all
  DirectoryIndex index
.php
  AllowOverride None
  Options 
+FollowSymLinks
  AddDefaultCharset Off

<IfModule mod_php5.c>
  
  
php_value memory_limit 128M
  php_value max_execution_time 18000
  php_flag magic_quotes_gpc off
  php_flag session
.auto_start off
  php_flag suhosin
.session.cryptua off
  php_flag zend
.ze1_compatibility_mode Off
  php_flag zlib
.output_compression on

</IfModule>

<
IfModule mod_rewrite.c>
  
  
RewriteEngine on
  RewriteBase 
/
  
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteRule 
^(index.php/)?minify/([^/]+)(/.*.(js|css))$ lib/minify/m.php?f=$3&d;=$2    
  RewriteCond 
%{REQUEST_URI} !^/(media|skin|js)/
  
RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond 
%{REQUEST_FILENAME} !-d
  RewriteCond 
%{REQUEST_FILENAME} !-l
  RewriteRule 
.* index.php [L]

</IfModule>
  
  <
IfModule mod_security.c>
   
SecFilterEngine Off
   SecFilterScanPOST Off
  
</IfModule>
    
  <
IfModule mod_expires.c>
   
ExpiresDefault "access plus 1 year"
  
</IfModule>
 
<
IfModule mod_deflate.c>
       
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)$ no-gzip dont-vary
       Header append Vary User
-Agent env=!dont-vary
</IfModule>


<
IfModule mod_ssl.c>
SSLOptions StdEnvVars

</IfModule>
</
Directory>


6/ Save that as myhtaccess.conf (naturally use your own domain path, and you would also have to install fooman speedster if the - RewriteRule ^(index.php/)?minify/([^/]+)(/.*.(js|css))$ lib/minify/m.php?f=$3&d;=$2 - line in the code was going to be of any use to you)

(you can call this whatever you like, but be sure to change it in the httpd.conf)

7/ The httpd.conf handily tells you exactly where you need to upload the new myhtaccess.conf file to:

In my case it was:

/usr/local/apache/conf/userdata/std/2/yourcpanelname/mydomain.com/myhtaccess.conf

Ok. Looks great. However, when I went to that location in my ftp client I found that up to:

/usr/local/apache/conf

Was there, but that the rest wasn’t.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stuarts
Member
 
Total Posts:  66
Joined:  2009-03-16
 

I am on Cpanel, so figured it may have something to do with that. And sure enough in the cpanel doc here - http://www.cpanel.net/products/cpwhm/cpanel11/apache_config_system_final.pdf - Is the following explanation.

Problem: User wants to add something to a virtualhost.
Solution: It is possible to create a custom virtualhost template and have it used
instead of the default virtualhost templates. You’d need to add a line to the
virtualhost datastore telling it the location of the template. Usually minor
configuration changes can be most simply made via the user’s .htaccess files or
included into httpd.conf under /usr/local/apache/conf/userdata. The
include directory structure is not created automatically, but use the following file
structure:
/usr/local/apache/conf/userdata/(ssl|std)/(1|2)/<user>
/<domain>/<something>.conf - Individual VirtualHost
/usr/local/apache/conf/userdata/<something>.conf - All VirtualHost
containers
/usr/local/apache/conf/userdata/[ssl or
std]/<something>.conf - All VirtualHost containers for SSL or
standard VirtualHosts
/usr/local/apache/conf/userdata/[ssl or std]/[1 or
2]/<something>.conf - All VirtualHost containers for SSL or
standard VirtualHosts with version specific settings
/usr/local/apache/conf/userdata/[ssl or std]/[1 or
2]/<user>/<something>.conf - All of a users VirtualHost
containers for SSL or standard VirtualHosts with version specific settings
/usr/local/apache/conf/userdata/[ssl or std]/[1 or
2]/<user>/<domain>/<something>.conf - Individual VirtualHost
container for SSL or standard VirtualHosts with version specific settings
Includes are located as the final directive in the VirtualHost container. Default
values can usually be overridden via the include files. Include files beginning with
“cp_” are reserved for cPanel settings and can and will likely be automatically
rewritten. After adding any new include files, the required VirtualHost include
statements can be ensured by running /scripts/ensure_vhost_includes
with the proper arguments.

Ok. So basically, I just created the rest of the structure in my ftp client, and set each of the new folders to 777. I also set the myhtaccess.conf to 777

ie So that the structure was:

/usr/local/apache/conf/userdata/std/2/yourcpanelname/mydomain.com/myhtaccess.conf

8/ I then uploaded the altered httpd.conf to /usr/local/apache/conf/http.conf (which is where it was on my server)

(Remember I have also uploaded /usr/local/apache/conf/userdata/std/2/yourcpanelname/mydomain.com/myhtaccess.conf)

Note: I did also try just pasteing the contents of myhtaccess.conf directly into the httpd.conf; to see if it was faster, but in my tests it made no difference, so I left it using the include setup, as that seemed to be neater)

9/ Apache then needs to be restarted for the changes to take effect.

On a cpanel server you do this by logging into WHM. On the left is a section called ‘Restart Services’. If you click on ‘HTTP Server (Apache)’ then that will restart the Apache service.

10/ You can now delete your original .htaccess (assuming everything worked)

Conclusion:

This wasn’t the magical speed transformation for me, that it has been for others.

I would say 2/10s of a second faster.

My pages load in the 1.5 - 3 second range. Most around 2. This probably dropped the average to about 2 seconds.

Magento is just plain slower then solutions like creloaded, which in my tests often load in about 1 second.

Magento is useable, but really could do with being faster

When you consider the amount of speed improvements I have tested out it seems that about 1.5 seconds is about as quick as it gets on Magento.  And even that is uncommon. 2 is more normal. Whilst oscommerce solutions are considerably faster.

Hopefully the Magento guys realise that bells and whistles are not enough. And that they need to find ways of improving the core code of this to speed it up, as even with all these tweaks, it is still considerably slower then other cart solutions.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stuarts
Member
 
Total Posts:  66
Joined:  2009-03-16
 

Thought I would bump this one up to the top, as I have added another 3 methods I have found into the guide above (making 18 so far that I have found) plus a couple of others from Discovery, and a good clarifying post from Francois.

Feel free to add new ones, or clarifications to the others grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
J_T_
Mentor
 
Avatar
Total Posts:  1961
Joined:  2008-08-07
London-ish, UK
 

http://talks.php.net/show/perf_tunning/1

Couple of tips from the experts themselves.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stuarts
Member
 
Total Posts:  66
Joined:  2009-03-16
 

Good one JT.

Set me to thinking that there must be optimisation tips floating about for MySQL…

http://forge.mysql.com/wiki/Top10SQLPerformanceTips

Just need to figure ou which ones have the most impact on Magento grin

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 7