How To Increase PHP Memory Limit

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 we will show two different ways on how you can increase the php memory limit in your server.

Check PHP Memory Limit

You can check by creating a file called info.php in /var/www/html/ with the following content:

<?php phpinfo(); ?>

php-memory-limit

Increase PHP Memory Limit

Method 1. Changing memory limit from php.ini

First find locate the php.ini file used by your web server.

 #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

 #memory_limit = 64M ;Maximum amount of memory a script may consume (64MB)

Restart webserver

#service httpd restart
or
#service nginx restart

Method 2. Changing memory limit using .htaccess

Find the “.htaccess” in your root directory of the specified domain, edit the .htaccess file in the web root directory. Look for the section:

 #php_value memory_limit 64M; Maximum amount of memory a script may consume (64MB)

Edit your wp-config.php file, if you are using WordPress

define('WP_MEMORY_LIMIT', '256M');

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

You Might Also Like: How To Install PHP 5.5 on CentOS

Leave a Reply