I have (only) 512MB to spare. The only thing running on my VPS is PHP/MySQL and on top of it Wordpress. No mail server or any other application, just Wordpress and LAMP stack.

How to decide how much memory to give to PHP and Wordpress? Right now PHP is allowed to have 128MB, how much is safe amount to increase it? I've tried to Google the question but never really found any answers.


TL;DR - Don't bump your memory limits for the sake of it. For a standard PHP application like WordPress, 128MB is huge and should be enough for 90% of your needs.

However, there are a few important facts here:

PHP Memory Allocation is per-script/process

As per the PHP documentation for the max_memory option:

This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server.

An important distinction to make is that this setting doesn't set the amount of memory that is available to all PHP processes - it sets the maximum available memory for one PHP process.

When Apache receives a request for a PHP page, it forks a PHP process, which dies as soon as its work is done. Any memory used during that request is then released back to the OS and the entire cycle starts again with the next request.

You should never have to tweak the max_memory settings unless you are seeing "Out of memory" errors from PHP itself, and that generally only happens when you:

  1. Are working with large data-sets, which if you're running a WordPress website I extremely doubt.
  2. Have a memory leak or other problem which means that memory isn't being released back to the OS, and the correct response to this type of problem is to investigate the source problem, rather than just bumping limits.

Apache Tuning

If you're interested in tweaking for performance, you should look at the Apache MaxClients and associated options within the prefork module.

I would typically reserve 50MB for the kernel and other system processes, and dice up the rest for Apache and MySQL - there are various online guides detailing how to do this (which I strongly suggest that you read), but the general idea is:

  1. Run top and check how much memory is used by your average Apache process (this is the RES column)
  2. Take your total memory, subtract the amount you want to reserve for other processes, and divide by the number above. This is the number of simultaneous connections that Apache can handle before it will need to turn clients away.
  3. Edit your Apache configuration and set the MaxClients option to this number.

Note I mentioned simultaneous connections above, not visitors on your website. The two are not the same.

  • Wow.. what a great answer, really appreciate it. – Badr Hari Apr 27 '15 at 10:57

As Craig Watson already told, you should not mess with PHP memory limit if not really necessary.

Anyway, it is not possible to correctly size the server without a profound understanding of your workload. I suggest you to simulate a realistic load and in the meanwhile to monitor your server resource allocation/usage.

For what it matters, 512 MB are very few for any production server. In fact, they are barely adequate even for testing purpose.

  • Thank you for your comment, is 512 really that little for a wordpress blog? I also use heavy caching. – Badr Hari Apr 27 '15 at 10:57
  • Yes, it is little because you need Apache, PHP (running a heavy application as Wordpress) and MySQL running all at once. – shodanshok Apr 27 '15 at 11:30

You measure. You run it at your workplace in a VM of similar specs and put a load test on it. Simple like that. Given that any half decent tablet can run visualization that is also not really an issue.

  • I was more thinking about what is the maximum ram I can assign until it's bad for the linux system itself. The question is not so much about wordpress optimization but rather how much is safe to give to PHP. – Badr Hari Apr 27 '15 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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