I have a server with a lampp stack and a php based software. This server has very low memory and unfortunately it's not an option for me to change now or increase memory. At least short term.

The low memory impact on the performance is very noticeable. The server is swapping a lot.

Changing from apache to another http server is not an option on short term due to a couple of dependencies.

Can nginx used as a reverse proxy with caching, in the same server, be an alternative to improve performance?

I've used nginx before in other settings with high success. In this case I am very limited. The upside of this solution is that it will free apache from serving static content, in other hand nginx will also consume memory and add up to an already slow system.

3 Answers 3


This is extremely dependent on the specific workload of the server and why it is consuming as much RAM as it does.

If the stuff generated by your PHP scripts is essentially static (and you have set appropriate cache control headers) so that a caching proxy can actually reuse generated content, it might work (or not). If not, you will just add more strain to the memory.

Generally, if you are severely resource-constrained, switching web servers is not a magic bullet that will fix this. The solution to low RAM is to add more RAM ...

  • Thanks. I partially disagree. The solution to low memory can be optimization. Sometimes things just use too much memory as they are by default.
    – nsn
    Nov 5, 2015 at 15:00
  • Optimization has its limits. You said yourself your server is severely resource constrained. RAM is a very cheap resource and up to a certain limit, it's cheaper to just add RAM instead to try to optimize just a little more.
    – Sven
    Nov 5, 2015 at 15:03

Caching would use memory anyway (and even Apache can do that), so what's the advantage with that? At most to improve performances you can set nginx to serve the static content, while proxying instead to Apache for dynamic content. Of course if:

  • you got enough static content on your website that it would justify that;
  • the memory usage is due to the number of Apache threads (concurrent users) and not to a few very memory hungry scripts.

You might also want to try to lower the maximum number of threads and spare threads in Apache first, this might make your website react a little slower but if you tweak it a little bit and you don't have sudden usage spikes you should be fine.

  • I did that. The problem is really the apache processes. They just use too much memory with all the modules it loads.
    – nsn
    Nov 5, 2015 at 14:58

You can use Apache in worker mode (instead of prefork), without mod_php and use PHP in a FPM pool.

Apache will serve static content with small threads instead of big processes (that contains mod_php), and the FPM pool will only serve dynamic content.

This configuration will also allow you to use different php version and configuration in different virtualhosts.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .