What is memory_limit in PHP settings?
memory_limit is a setting managed by a PHP option that sets the maximum amount of memory a script can use. This value should be set at least as large as post_max_size.
Why does the Memory limit error happen?
Sometimes when you run a PHP script, you will receive an error like "Fatal Error: Allowed memory size of XX bytes exhausted". It happens because the memory allocated to the PHP script has been exhausted, and the script cannot finish executing. It is called a PHP memory limit error.
The amount of memory PHP can use defined by the term memory_limit in the PHP settings on the server. With the help of cPanel, you can change this value as you like.
Below are the steps to change the PHP Memory Limit from cPanel.
Step 1: Log into your cPanel account.
Step 2: Go to the Software section and click on the Select PHP version.
Step 3: In the PHP Selector window, click on Options.
Step 4: Scroll down the screen and select the memory_limit option.
Step 5: Click on the down arrow. It will show the possible value you can choose. Select the value which you want to set.
Once you select the value, it will be saved automatically and set for the specific PHP version.
How to verify the value of the memory limit?
You can verify that your changes have taken effect by creating a PHP file with the following content. You can create a file called info.php. In the file, type the following code.
<?php
phpinfo();
?>
Please save the file and upload it to your domain's public_html folder. Our domain name is demovpstest.com, and files can be viewed at https (https://demovpstest.com/info.php).
You can now check your PHP settings in your browser by simply going to https://demovpstest.com/info.php in your browser. Look for the "memory_limit" option to see if the new value you changed has taken effect. In my case, it is correctly displayed as 256M, as in the image below.
This is a very convenient and easy way to get rid of the "Allowed memory size of XX bytes has been exhausted" message as you can always change these configuration values in cPanel.
That's all.