In this tutorial, we will show you how to increase the PHP memory limit on a Linux server. 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.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges.
Increase PHP Memory Limit
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo yum clean all sudo yum update
Step 2. Check PHP Memory Limit
You can check by creating a file called info.php in
/var/www/html/ with the following content:
<?php phpinfo(); ?>
Step 3. Increase PHP Memory Limit on Linux system.
Method 1. Changing the memory limit from php.ini
First, find locate the php.ini file used by your web server.
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 Nginx or Apache 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 webroot directory. Look for the section:
php_value memory_limit 64M ;Maximum amount of memory a script may consume (64MB)
Congratulations! You have successfully increased the PHP memory. Thanks for using this tutorial to changing the PHP memory limit Linux system. For additional help or useful information, we recommend you to check the official PHP website.