This is a pretty general question, so there are number of ways to answer it. The simplest is to guess that you probably got all the elements for your LAMP stack from the same place: your Linux distribution (the "L" part of the stack). This is fine. It's part of the added value of a distro to give you lots of software, all of it tuned and tested to work with the distro you receive. So the simple answer is: upgrade your LAMP stack when you upgrade your operating system.
Other than that, is there some performance objective that is not being met? Would you like a more secure version of Apache, for instance? In that case you might find one for free, or you might want to pay for one, and then substitute it in the stack for the one that came with your distro. You may find that your substitute comes in different flavors to work with different distros.
You can find more on the ins and outs of software stacks by looking at this question.
This was first published in November 2006