Search

How to Increase PHP Memory Limit in WordPress

When setting up WordPress manually or using hosting other than WordPress-specific hosting, it’s possible to encounter a low PHP memory limit. This limit is essential for maintaining server performance and preventing issues or crashes caused by PHP scripts consuming excessive memory. By setting an upper boundary on memory usage, the limit acts as a safeguard against runaway scripts or memory leaks.

However, if the PHP memory limit is set to a very low value, you may encounter errors on your site or experience accessibility issues, particularly when installing resource-intensive plugins like page builders. For example, popular page builders such as Divi require a PHP memory limit of at least 128 MB, while Elementor recommends a limit of 256 MB. Insufficient memory allocation can hinder the proper functioning of these plugins and negatively impact your site’s performance. To ensure optimal compatibility and performance, it is crucial to adjust the PHP memory limit accordingly.

This tutorial will show you how to find out your WordPress current PHP memory limit and increase it to the desired amount.

Find Out your Current PHP Memory Limit

To check your site’s current PHP memory limit, you can use the Site Health tool which you can access from the Tool menu from your WordPress dashboard. This tool helps you to monitor and give valuable insight into your site’s health on the Status tab and you can find most of your server and WordPress configuration info on the Info tab including the PHP memory limit which is located on the Server block.

Increasing the PHP Memory Limit

Once you find out your site’s current PHP memory limit and you think it’s not enough for you, there are several methods you can try to increase the PHP memory limit. Let’s explore some of these options below.:

  • By modifying the PHP.ini file
  • By modifying the wp-config file
  • By modifying the .htaccess file
  • By creating the .user.ini file

The PHP memory limit is ultimately determined by your web host. In some cases, your website may be configured to use fewer resources than what your host actually offers. Adjusting your files can sometimes resolve this issue. However, if your host has set a hard-coded limit that is too low, it will not be possible to increase the memory limit manually, regardless of the value you set.

By Modifying the PHP.ini File

The PHP.ini file is where you can usually find PHP-related rules including memory limit and upload size limit settings. This file contains the default configuration for running applications that require PHP like WordPress. When PHP starts to run, it looks for the php.ini file and loads it.

The location of the main php.ini file varies greatly by the environment you’re running PHP with, so It’s difficult to guess the exact location of the file. One of the approaches to locate the currently loaded php.ini file, you can create a .php file with the name phpinfo.php in your web root (public_html in most cases) folder and then load that file on your browser. The content of the PHP file is as follows:

<?php
  phpinfo();
?>

Once you created the file, try to load it on your browser with this URL format www.yourwebsite.com/phpinfo.php. And the information displayed on that page will look like this.

As you can see in the above image, our main php.ini configuration file is located in /opt/alt/php-ffpm74/usr/php folder.

Once you find yours, open up the file from the file manager. Now, find the memory_limit configuration and modify its value to your desired amount.

Continue by saving the file to apply the new memory limit configuration value.

By Modifying the wp-config.php File

If you are unable to access your PHP.ini file due to restrictions imposed by your hosting plan, an alternative option is to modify the wp-config.php file located in your web root folder.

The wp-config.php file contains important configuration settings for your WordPress site and can be edited to make certain PHP-related changes. By adjusting the necessary parameters within the wp-config.php file, you can achieve similar effects to modifying the PHP.ini file.

However, please note that modifying the wp-config.php file should be done with caution, as incorrect changes can potentially disrupt the functionality of your WordPress site. It is always recommended to create a backup of the original file before making any modifications.

Once you’re ready, head over to your web root either via your hosting file manager or FTP to open the wp-config.php file and find the memory limit configuration line:

define('WP_MEMORY_LIMIT', '128M');

Replace the number with the desired amount, then save the file to apply the changes.

If you can’t find the memory limit configuration on your wp-config.php file, don’t worry, you can just add the configuration line yourself right after the define( 'WP_DEBUG_LOG', false ); line in the file.

By Modifying the .htaccess File

Another option to increase the PHP memory limit is by editing the .htaccess file which is also located at your web root folder.

The .htaccess file starts with a dot because it is considered a hidden file. Hidden files are typically not displayed by default in file managers to avoid cluttering the view. If you cannot find the .htaccess file in your web root folder, it is possible that your SFTP file manager is configured to hide these types of files. You may need to adjust the settings of your file manager to show hidden files if you want to locate and work with the .htaccess file.

To increase the PHP memory limit, add the following to your .htaccess file just before the #END WordPress line:

<IfModule mod_php7.c>
    php_value memory_limit 64M
</IfModule>

By Creating a .user.ini File

.user.ini file is a file that controls the PHP settings in a single directory. There are only certain directives allowed to use in this file, including the directives to configure the PHP memory limit. The directives in .user.ini will override the main php.ini configurations, so if you want to give different max limits for each of your websites, feel free to create or modify the .user.ini file on each website web root.

Start by opening up your hosting file manager and then navigating to your web root folder (public_html in most cases). Create a file and name it .user.ini then add the following configuration line to the file.

memory_limit = 128M

Once you’ve added the configuration line, save the file to apply the changes and get a new memory limit for your website.

The Bottom Line

The PHP memory limit acts as a safeguard against runaway scripts or memory leaks which can cause server performance issues or crashes which is great. But if the memory limit is too low then you might end up in a problem when you try to install most of the page builder plugins or other resource-intensive plugins. This tutorial shows you how to increase the PHP memory limit using several methods that might work for your site.

This page may contain affiliate links, which help support our project. Read our affiliate disclosure.
Hendri Risman

Hendri Risman

Hendri is a WordPress expert and a writer staff at WPPagebuilders. He writes solutions on how to get things fixed in WordPress a lot. Mostly without involving a plugin.
Want to save yearly expense up to $219? why not?

Leave a Comment