If you have seen an error like ”Fatal Error: PHP Allowed Memory Size Exhausted” in webserver logs or your browser, this means that PHP has exhausted the maximum memory limit. This tutorial will show two different ways on how you can increase the php memory limit.
Check PHP Memory Limit
You can check by creating a file called info.php in /var/www/html/ with the following content:
1 2 3 | <?php phpinfo(); ?> |
Increase PHP Memory Limit
Method 1. Changing memory limit from php.ini
First find locate the php.ini file used by your web server.
1 | #nano /etc/php.ini |
Search “memory_limit” in your php.ini, and change it. If no “memory_limit” found, add the following line at the end of php.ini
1 | #memory_limit = 64M ;Maximum amount of memory a script may consume (64MB) |
1 2 3 | #service httpd restart or #service nginx restart |
Find the “.htaccess” in your root directory of the specified domain, edit the .htaccess file in the web root directory. Look for the section:
1 | #php_value memory_limit 64M ;Maximum amount of memory a script may consume (64MB) |
Congratulation’s! You have successfully increase PHP memory limit. Thanks for using this tutorial for increase PHP memory limit linux system. For additional help or useful information, we recommend you to check the official PHP web site.