How to change PHP memory limit in Linux server?

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 below type of errors in running PHP application which require more PHP memory than default 64 MB.

There are many ways you can increase this limit. You can increase it from WHM, .htaccess file and also from php.ini file.


How to change PHP memory limit from WHM (version 11.24.x)?

You can increase the default PHP memory limit value from “PHP configuration Editor” option of WHM. You will find “memory_limit” directive in core section. Just increase the limit from 64 MB to 256 MB (or any value in MB you wish). Click on 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 any how. You just need to enter below 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 linux environment you will find this file in /usr/local/lib/. However, it may be different since administrator changed it. You can find the exact path by placing phpinfo.php file in your domain. Simply use below code in phpinfo.php file and save.


<?

phpinfo();

?>


It will display you php.ini path inConfiguration File (php.ini) Path” value. It will also display you some other PHP loaded modules (It will only display if enabled) like GD library, MySQLi, Zend Optimizer, Ioncube etc.


Once you got 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 below command once you are in /usr/local/lib directory:


Note
:  I would recommend to backup the existing php.ini file before you make any changes. Since if by mistake you will mess it then it may lead to stop your PHP functioning. So simply copy existing php.ini file somewhere and then start editing the existing one.

vi php.ini


You will find “memory_limit” directive inside “Resource Limit” section. Just modify this value to the limit you wish to set and save exising php.ini file. In vi editor Press Esc -> colon (:) -> wq to save the file.


You will need to restart your apache server in order to make the changes effective. You can restart it by executing following command through SSH:


apachectl -k restart


Simply check phpinfo.php file and make sure the changes are reflected properly.


Thanks!
Add comment Share
Hosting Companies insights
1301 Web Hosting Reviews A trusted source of genuine reviews. Learn Reviews
2579 Web Hosting Companies Ever-growing pool of web hosting providers. Browse Providers
2066 Web Hosting Coupons Exciting web hosting deals available here Browse Coupons