← ServerPilot Docs

How to Reduce PHP and WordPress Memory Usage

Every server has a limited amount of memory, also known as RAM. The amount of memory your server has is determined by the type of server you're paying for at your server provider.

When a server runs out of memory, the server must kill processes so the server can keep running. This is the most common cause of MySQL crashing: the server ran out of memory and had to kill MySQL.

The best solution to running out of memory is to upgrade to a server with more memory.

What Uses Memory

The mount of memory your server uses is related to many factors, including

  • the number of apps on the server,
  • what types of apps they are (WordPress, Magento, Drupal, Laravel, etc.),
  • any app plugins, such as WordPress plugins,
  • the amount of concurrent traffic individual apps receive,
  • the PHP version you're using,
  • whether you've added third-party PHP extensions, and
  • whether you're using PHP's opcache.

Average Memory Usage

The operating system and core services use around 150MB of memory.

Each simple app (small codebase, one database, low traffic) uses about 50MB of memory.

So, for example, with 10 apps your server would normally use about 650MB of memory. That is,

150MB (OS memory usage) + 10 (number apps) * 50MB (app memory usage) = 650MB

Decreasing Memory Usage

If you need to lower memory usage, you can do a few things to save memory.

Upgrade Each App's PHP Version

Each new version of PHP includes optimizations that reduce that amount of memory used internally by PHP to execute your scripts.

You should use the newest version of PHP that your app supports.

Disable WordPress Plugins

Disable any WordPress plugins that you don't need.

Some WordPress plugins increase memory usage significantly. By disabling plugins you don't need, you can save memory.

Disable Third-Party PHP Extensions

If you've added third-party PHP extensions like New Relic, these will increase memory usage.

If you need these extensions, you should not disable them. However, if you've added them and aren't using them anymore, you should disable them.

Disable the PHP Opcache

PHP has a built-in opcache that is enabled by default.

The entire purpose of PHP's opcache is to speed up your scripts and save CPU by storing compiled PHP scripts in memory.

If you'd rather to have slower apps and increased CPU usage to save memory, you can disable the opcache.

Learn how to disable the PHP opcache.

Last updated: June 28, 2023

Launch your first site in 5 minutes