Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What performance tips can be offered to someone running a LAMP server?

In the instance that something is Distribution specific, I'm targeting Debian.

share|improve this question

3 Answers 3

up vote 26 down vote accepted

it really depends on your workload.

  • for L part

    • get a lot of memory,
    • if you can go over 4GB, go 64bit.
    • for partitions where your content, logs and mysql data are use mount options: noatime, nodiratime.
    • use separate physical drives / raid sets, ideally keep sql data, logs, content you serve - each on separate spindle.
  • for A part of your stack - well maybe you want to replace it completly with nginx or lighthttpd, or maybe just leave apache for dynamic content and have separate server (like those two or mathopd) for static content. take a look here for more options. if you are going to run both apache and other server at the same box - 2nd ip address will be handy. to decrease latency for end-user use http/1.1 with keep-alive. consider using cdn for static content.

  • for M part of your lamp - take a look at mysqlperformanceblog. from the top of my head:

    • log slow queries,
    • give enough memory,
    • consider using innodb.
    • if you have a lot of text to search across - use sphinx and have batch job that rebuilds index.
    • consider killing queries that run longer than XYZ seconds. it's better to upset 1% of users than to bring the whole site down at the peak time. but that really depends if you process cash transactions or show nice pictures.
    • use memcached if you can to cache result of more 'expensive' sql queries. keep in mind to invalidate the cache when you change content of sql. on the other hand i have quite few sites where all data fits in memory comfortably and for that mysql is blazing fast and there is no need of additional cache.
  • for P

    • set execution timeout for scripts.
    • consider using some php accelerator / opcode cache. i was quite satisfied with xcache, but i dont use it now.
    • if you have cpu intensive processing - cache results and store them in sql or memcached

not really performance tip - but do take offsite backups. really.

share|improve this answer
1  
if i may add this, i recently blogged about secure backups with push and pull strategies via amazon s3. not viable for bank data, but everything you will trust amzon with should be fine. logaholic.de/2009/05/21/… –  Karsten May 24 '09 at 10:28
    
i have actually noticed that blog post before you commented ;-]. nice one anyway. you can always encrypt your backup to make it more secure. –  pQd May 24 '09 at 10:47

For the P part, you could consider opcode caching with i.e. APC. One could also consider mod_fastcgi with php instead of the default mod_php.

share|improve this answer
    
I really like eAccelerator. It gives the best performance for my sites. –  TheHippo May 24 '09 at 17:20

I really suggest separating MySQL and Apache/PHP on two different machines.

For example, I had one machine (C2D E6600) that always spiked to 2.0 and above load average. I put the MySQL on a second machine (P4C 3Ghz) and after that both load averages did not go above 0.2-0.3. So I went from a really slow site to a fast site with two servers having a lot of performance margin.

share|improve this answer
    
good point. i can only speculate that your bottleneck could have been IO subsystem / drive responsiveness. maybe then separating data on two different drives / having fine disk controller could do the trick as well. anyway more memory, and more cpus is always good, but then you get more possible points of failure as well. –  pQd May 24 '09 at 13:28
    
Well, I'm not so sure it was disk I/Os because most (let's say 90%) SQL hits were cached. I was thinking about CPU context switches but I don't know if that can actually play a significant role. –  Antoine Benkemoun May 24 '09 at 13:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.