Skip to main content

How to Increase the PHP Memory Limit?

Updated over 3 weeks ago

The memory_limit variable in PHP comes with a default value, but it is fully adjustable according to your needs in the PHP.ini file. Below, we provide you with a step-by-step guide on how to modify it through cPanel, considering the two versions of PHP and the different management interfaces available.


Step 1: Check the PHP Handler

Before starting, make sure you know the PHP handler in cPanel to adjust the PHP memory limit. The PHP handler is a mechanism that determines how PHP requests are processed on your server. You can find this information in the "MultiPHP Manager" or "PHP Selector" section, depending on your configuration.

How can I know which handler I am using?

To know the PHP handler you are using, go to the cPanel section Software >> Select PHP Version. Once inside, check where it says Handler by:

If you are using CloudLinux PHP Selector, it will appear like this:

If using MultiPHP Manager, it will look like this:


Step 2: Adjust with CloudLinux PHP Selector

  1. Navigate to the "Software" section in cPanel.

  2. Look for and select "Select PHP Version" or "PHP Selector".

  3. Select the PHP version you are using.

  4. Click on the "Options" tab.

  5. Look for the option "memory_limit" and set the desired value in megabytes (M).

  6. Save the changes.


Step 3: Adjust with MultiPHP Manager

Access the MultiPHP INI Editor:

  1. Navigate to the "Software" section in cPanel.

  2. Look for and select "MultiPHP INI Editor".

Select the Path:

  • Choose the location you need to modify. For values associated with a domain, subdomain, or all domains in your Hosting account, select "Home directory".

Find and Modify memory_limit:

  • Locate the "memory_limit" variable in the configuration.

  • Enter the desired value in megabytes (M). Example: set it to 1024M.

Save the Changes:

  • Make sure to save the changes made.

🎉 Congratulations! You have successfully adjusted the PHP memory_limit variable for your site or Hosting plan. This process allows you to adapt the memory configuration according to the specific needs of your application.


Optional Step: Adjust the Memory Limit in WordPress (wp-config.php)

In some cases, after adjusting the memory limit in cPanel (either via PHP Selector or MultiPHP INI Editor), WordPress or some plugins may not properly detect the new value. This can occur due to specific WordPress settings or limitations in how plugins handle memory. To ensure WordPress recognizes the correct memory limit, it is recommended to adjust it directly in the wp-config.php file.

Instructions:

Access the wp-config.php file:

  1. Log in to your cPanel.

  2. Go to File Manager.

  3. Navigate to the root folder of your WordPress installation:

    • For the main domain, go to public_html.

    • For additional domains or subdomains, go to the corresponding folder (you can check the path in cPanel > Domains > Document Root).

  4. Locate the wp-config.php file.

Edit the wp-config.php file:

  1. Right-click on the file and select Edit.

  2. If a notification about encoding appears, click Edit to continue. You can also select Disable encoding check for future edits.

  3. Look for the line that says:

/* That's all, stop editing! Happy blogging. */

Just before that line, add the following code:

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

(Replace 1024M with the memory value you have configured on the server).

Save the changes:

  • Click Save Changes to apply the modifications.

Verify the changes:

  • Make sure the changes have been applied correctly. You can use a plugin such as WP Memory Usage or check the WordPress status in Tools > Site Health within the WordPress admin panel.

  • If you had a plugin that previously did not properly detect the memory limit (such as an optimizer, language plugin, or any other), review its settings again. After making the changes in the wp-config.php file, they should now display the new memory limit set.


Important Note:

The value of WP_MEMORY_LIMIT must not exceed the limit configured on the server (memory_limit in PHP.ini or PHP Selector). If the value is higher, WordPress will not be able to use more memory than the server allows.

This step is optional and only necessary if WordPress or any plugin does not detect the memory value configured in cPanel.


We hope this information has been useful and provided you with valuable guidance. Thank you for trusting us, and don’t hesitate to contact us if you need further assistance or have any questions!

Did this answer your question?