PHP is a scripting language used primarily on the web and is highly customizable and has many settings that users can modify themselves. This article will advise you how to modify your php.ini file.
Fixing the “Allowed memory size exhausted” error
A common issue when using free open source software or other PHP intensive programs is the “exhausted memory” error. If you have a PHP memory error on your site, you can increase the memory limit PHP uses for the scripts. This memory_limit can be changed in the php.ini in the public_html folder in your hosting account. This error can creep up in your website during the normal development process. The following is an example of the error:
Fatal error: Allowed memory size of 268435465 bytes exhausted
(tried to allocate 280559520) in Unknown on line 0
This is due to php variable data being stored in the memory that is not cleared while the php scripts are running. The following steps will explain how to set the php.ini to allow a larger amount of memory use.
- Login to your cPanel
- Go to the File Manager. Select the Web root (public_html/www) directory and click Go.
- Find the php.ini file in the public_html (If you do not have a php.ini in your public_html files, you can have our tech support staff restore the php.ini to your public_html directory)Open the php.ini with the code editor.
- Find the following section in the php.ini file.
123max_execution_time = 30max_input_time = 60memory_limit = 128M
Try increase the memory_limit value to 256M. If the php memory_limit is already at 256M, you can increase it to 512M.
=> Save the changes.
- In order for your memory limit to take effect you will need to make the php.ini recursive in the .htaccess.Now visit the site. You should not see the “Allowed memory size” error anymore. If the error still shows on your website, there may be a setting within the software itself that is overriding the change or the php.ini in the public-html may be overriden by another setting elsewhere. If this is the case, you can contact our our tech support staff to have them look into the error further.
Modify the PHP.INI file
The following steps help you edit the PHP.INI file.
- Login to the cPanel.
- Find the File Manager in File section of the Cpanel. Review our tutorial on using the Code Editor within the File manager if you’re looking on information how to use it.
- Navigate to the directory where you will either save or edit the PHP.INI file and then select the file and use the Code Editor. To open the file, you can click on it to select the file and then click on the Code Editor icon in the menu bar of the File Manager. You can also right-click with your mouse and select Code Editor from the menu that appears.
- Edit the section of the PHP.INI that you wish to change.
- Click on SAVE CHANGES in the top right hand corner in order to save your modifications or additions to the file.
Don’t have a php.ini file
Only users running on a server with PHP loaded as a “CGI module” will have a php.ini file. The php.ini file by default will be located at public_html/php.ini. If you do not see a file named php.ini in your public_html, please contact our Support Department and request that we create one for you.
Made changes to the php.ini file but do not see any changes!
The php.ini file is not recursive. Updating your php.ini values in public_html/php.ini will not affect PHP files in subfolders of your public_html, such as public_html/staff. To correct this problem, you can make your php.ini file recursive so that it affects all sub folders.
That’s all, hopefully this article helped you know how to modify the php.ini file and fixing the “Allowed memory size exhausted” error as well. If you have any further questions for us, don’t hesitate to put it up in the comments. See you again in orther tutorials!