Increasing PHP memory and limits

Are you getting error messages like "Allowed memory size exhausted" or "Maximum execution time exceeded"? Then the PHP limits are too low for your website. In this article, we explain how to increase these limits and when upgrading is a better solution.

Why memory limit errors occur

PHP has default limits to protect server resources. These limits are:

  • memory_limit - How much RAM a script may use
  • max_execution_time - How long a script may run
  • upload_max_filesize - Maximum upload size
  • post_max_size - Maximum size of POST data
  • max_input_vars - Maximum number of form fields

When your site exceeds these limits, you get an error or a white screen.

Common error messages

The message "Fatal error: Allowed memory size of 67108864 bytes exhausted" means that the script is trying to use more than 64MB of memory.

The message "Fatal error: Maximum execution time of 30 seconds exceeded" indicates that a script is running longer than allowed, often during imports or large operations.

Checking current limits

Before making changes, check what the current limits are.

Via WordPress

  1. Go to Tools > Site Health > Info
  2. Click on "Server"
  3. Here you see all PHP limits

Via phpinfo

Create a file info.php in your webroot with the code phpinfo() and open this file in your browser. Search for memory_limit. Delete the file after use.

For most WordPress sites:

  • memory_limit: 256M
  • max_execution_time: 300
  • upload_max_filesize: 64M
  • post_max_size: 64M
  • max_input_vars: 3000

Method 1: Via DirectAdmin

The most reliable method with Theory7 hosting.

Adjusting PHP Settings

  1. Log into DirectAdmin
  2. Go to "Select PHP version" or "PHP Settings"
  3. Find the setting you want to change
  4. Enter the new value
  5. Click "Save" or "Apply"

At Theory7, you can easily manage PHP versions and limits via DirectAdmin. The changes are immediately active.

Available settings

  • memory_limit - Increase to 256M or 512M
  • max_execution_time - Increase to 300 or 600
  • upload_max_filesize - Increase to desired upload size
  • post_max_size - Must be larger than upload_max_filesize
  • max_input_vars - Increase to 3000 for WooCommerce

Method 2: Via wp-config.php

For WordPress, you can increase the memory limit via wp-config.php.

  1. Connect via FTP to your website
  2. Open wp-config.php
  3. Add lines before "That is all, stop editing!" to set WP_MEMORY_LIMIT to 256M and WP_MAX_MEMORY_LIMIT to 512M

WP_MEMORY_LIMIT is for the frontend, WP_MAX_MEMORY_LIMIT for the admin.

Note: This only works if the server allows higher limits. DirectAdmin settings take precedence.

Method 3: Via .htaccess

For Apache servers, you can set limits via .htaccess.

  1. Open .htaccess in your webroot
  2. Add php_value lines for memory_limit, max_execution_time, upload_max_filesize, post_max_size, and max_input_vars

This only works on servers with mod_php. With PHP-FPM (standard at Theory7), DirectAdmin takes precedence.

Read more about .htaccess in our article Setting up the .htaccess file in WordPress.

Method 4: Via php.ini

Some servers support a local php.ini.

  1. Create a file php.ini in your webroot
  2. Add the desired settings like memory_limit, max_execution_time, etc.
  3. Save and test if the settings are active

Specific situations

WooCommerce webshops

WooCommerce requires higher limits:

  • memory_limit: 256M minimum, 512M recommended
  • max_input_vars: 3000 or higher for many product variations

Page builders

Elementor, Divi, and other page builders use a lot of memory:

  • memory_limit: 256M or higher
  • max_execution_time: 300 when saving large pages

Read more about Elementor optimization.

Import/export operations

For large imports or migrations:

  • max_execution_time: 600 or higher
  • memory_limit: 512M or higher

When is upgrading better?

Increasing limits does not always solve the problem. Consider upgrading when:

Structurally insufficient resources

If you constantly hit limits, your site is too heavy for your current package.

Many visitors

High traffic requires more memory per request. An upgrade to VPS provides dedicated resources.

Heavy plugins

Some plugins are resource-intensive. Upgrading is better than constantly increasing limits.

Performance problems

If your site is slow despite increased limits, upgrading to a faster package can help.

Tips for lower resource usage

Before upgrading, first try:

  • Cache plugin - Drastically reduces PHP execution
  • Image optimization - Smaller images load faster
  • Unused plugins - Deactivate what you do not use
  • Clean database - Remove old revisions and spam
  • Use CDN - Offloads static files from your server

Read our guide for WordPress speed optimization.

Verifying changes

After adjusting limits:

  1. Clear all caches (browser, WordPress, server)
  2. Check via phpinfo or Site Health if the values have been adjusted
  3. Test the function that failed before
  4. Monitor if no new error messages appear

Summary

The best approach for PHP limits at Theory7:

  1. First via DirectAdmin - This is the most reliable method
  2. Then wp-config.php - Specifically for WordPress memory
  3. Then .htaccess/php.ini - As fallback

If increasing does not help or you keep hitting limits, upgrading to a heavier package is the sustainable solution.