In this article, I have tried to explain how you can increase the default memory limit to run your PHP application. The default PHP memory limit in cPanel will be 64 MB. Users may receive the below errors in running PHP applications that require more PHP memory than the default 64 MB.
There are many ways you can increase this limit. For example, you can increase it from WHM, .htaccess file, and php.ini file.
How to change the PHP memory limit from WHM (version 11.24.x)?
You can increase the default PHP memory limit value from the “PHP Configuration Editor” option of WHM. You will find the “memory_limit” directive in the core section. Just increase the limit from 64 MB to 256 MB (or any value in MB you wish). Then, click on the Save button to submit the changes.
How to change from .htaccess file?
.htaccess is a hidden file (dot file) of Linux. You will find it inside every domain’s public_html folder. You can create it if you do not find it anyhow. You need to enter the below the line of code in this file:
php_value memory_limit 256MB
How to change it from php.ini file?
Php.ini is a default configuration file for PHP. In a Linux environment, you will find this file in /usr/local/lib/. However, it may be different since the administrator changed it. You can find the exact path by placing phpinfo.php file in your domain. Then, use the below code in phpinfo.php file and save.
phpinfo();
?>
It will display your php.ini path in the “Configuration File (php.ini) Path” value. In addition, it will also display some other PHP loaded modules (Only if enabled) like GD library, MySQLi, Zend Optimizer, Ioncube, etc.
Once you get the exact path, open it with any file editor tool like vi, pico, or nano. I am using vi editor and find it more comfortable. So type the below command once you are in the/usr/local/lib directory:
Note: I would recommend backup the existing php.ini file before you make any changes. Since if by mistake you will mess it up, it may lead to stop your PHP functioning. So simply copy the existing php.ini file somewhere and then start editing the existing one.
vi php.ini
You will find “memory_limit” directive inside the “Resource Limit” section. Just modify this value to the limit you wish to set and save the existing php.ini file. In vi editor Press Esc -> colon (:) -> wq to save the file.
You will need to restart your apache server to make the changes effective. You can restart it by executing the following command through SSH:
apachectl -k restart
Check phpinfo.php file and make sure the changes are reflected properly.
Click here to Check out the Best web hosting plans!
Thanks!
Sign up or log in