ini set memory_limit in PHP is not working at all

Asked : Nov 17

Viewed : 178 times

I had this working before :

echo ini_get("memory_limit")."\n";
echo ini_get("memory_limit")."\n";

I checked the PHP documentation and googled it, and I did not find anywhere that "memory_limit" had been deprecated.

Does anyone have a solution?

php memory apache2 debian 

Nov 17

3 Answers

For particular page you can define following lines in your code to change memory limit.

//Unlimited momory limit
ini_set('memory_limit', '-1');

//Fixed memory limit


if you want to set from server do follow below steps : php.ini

  1.  Open Terminal or Console and run php --ini Command.
  2. The command will return the physical path of php.ini file.
  3. In my case it was  /usr/local/etc/php/7.4/php.ini
  4. Simple you can go to the path and edit the php.ini file or directly edit from your terminal by run following command nano /usr/local/etc/php/7.4/php.ini
  5. Search for the string memory_limit
  6. Change the value that you want like (Unlimited momory limit : -1 , Fixed memory limit : 2048M).
  7. Save the file and restart your apache server by run following command sudo service apache2 restart.

That is it.

answered Dec 02

Type php --ini to find the configuration paths.

Change memory_limit to whatever value you need. Make sure that you are changing it on both these files: php.ini and conf.d/php-memory-limits.ini

(in my case, I use -1 to have unlimited memory (of course, not unlimited but as much as my computer can handle))

answered Dec 30

1. Changing the Memory Limit via wp-config.php:

This method will be comfortable for those who do not want to mess with the PHP.ini file. All you need to do is add define(‘WP_MEMORY_LIMIT’,’ XM’); in your wp-config.php file. Here too, ‘X’ is the number of MBs you wish to extend your limit to.


2. Increasing Memory Limit via PHP.ini file:

Most of the small shared hosting servers don’t allow users to access their PHP.ini files. If you are granted access, you can directly increase the memory limit here. If not, you can ask the host to allow you to create a duplicate PHP.ini file in your directory. The data or values in this duplicate PHP.ini file will override the data in the original file. To do this, you can simply create a file named PHP.ini in the directory where your WordPress website is installed. If you wish to increase the limit to X MB, you can enter the command memory_limit = X M; where X is a number.

memory_limit = 256 M;

3. Changing Memory Limit via wp-config.php:

This is an alternative method to the PHP.ini file method. You simply need to add the command: ini_set(‘memory_limit’,’ XM’); in your wp-config.php file that is placed in the root folder of your WordPress installation. Note: X is the number of MBs you wish to increase the memory limit to.


4. Modifying the .htaccess file:

In case you have a .htaccess file, you can simply add the command: php_value memory_limit XM in it, to increase the memory limit to X MB. Note: A default WordPress Installation won’t have a .htaccess file.

php_value memory_limit 256M

5. Contact your host:

If you are a nontechie or are new to all of this, it is better to get it done by someone who knows it all. Your host can be the best one to get in touch with. Contact him to help you increase your PHP Memory Limit.

answered Dec 30

Login and Submit Your Answer
Browse other questions tagged  php  memory  apache2  debian or ask your own question.