6

CentOS system.

Summary: changed memory_limit in master and local php.ini and yet no change in the local value for a particular virtual host.

Trying to improve performance, I set the memory_limit to 1024M in /etc/php.ini

phpinfo() shows Master and Local values for other virtual hosts on the server as 1024M. Changing the value in /etc/php.ini changes all values, except one.

One site is stuck with a local value of 256M.

I thought I found the problem: there is a php.ini file (which I didn't know about) in that site's root, and it had

memory_limit = 256M

I changed it to 1024M. Problem solved? No. And now I don't know where to look. Obviously, I've restarted apache (/etc/init.d/httpd restart), and that usually does the trick.

I also turned off APC cache, though I don't think it would cache ini files.

And finally, I tried adding this to the virtual host in httpd.conf:

php_value memory_limit 536870912

(yes, that would be 512MB) And that had no effect whatsoever.

What else could be the problem?

Thanks.

Buttle Butkus
  • 1,741
  • 8
  • 33
  • 45

3 Answers3

5

I found the answer. There was a hidden .htaccess file in the site root that was overriding all other values.

It had the line:

php_value memory_limit 256M

I changed it to:

php_value memory_limit 1024M

No need to restart apache, the memory limit went up to 1024M immediately.

——————

Also, if you load a phpinfo() page in your website root, near the top you can see configuration files affecting PHP. Search “config” and you’ll find a list.

Buttle Butkus
  • 1,741
  • 8
  • 33
  • 45
  • For me there is also such a file, but it is set to 5G and it still shows 756M. I grepped the whole folder after `php_value memory_limit` and changed everthing It found to 5G but does not change anything – Black Mar 23 '22 at 09:39
  • @Black can you load your `phpinfo()` page or run it in console and see which configuration files are affecting your setup? https://www.php.net/manual/en/function.phpinfo.php – Buttle Butkus Mar 23 '22 at 20:11
  • 1
    I figured it out, there were two .user.ini somewhere in the project. One in the root and one in pub folder. There the value was overriden. – Black Mar 24 '22 at 11:08
2

I just want to add that there can be another hidden file named .user.ini which can set php variables like php.ini.

The value in .user.ini was showing as Local Value even though I tried setting the value in php.ini. Here the value set using php.ini was updating the Global Value only and not the Local Value. Changing the value in .user.ini updated Local Value.

This was my issue and it took me hours to identify this. May save some time for some. :)

0

As another user pointed out, there is also a .user.ini which can change the value. CD to your root directory of the project where your phpinfo.php is located.

Execute find -type f -name "*.user.ini"

In my case I got:

./pub/.user.ini
./.user.ini
./vendor/magento/magento2-base/pub/.user.ini
./vendor/magento/magento2-base/.user.ini

So I opened ./.user.ini and ./pub/.user.ini and changed the value of memory_limit accordingly. Now check if the local value in your phpinfo has changed.

If not then you need to search the whole project with:

grep -iR memory_limit

And change all occurences.

Black
  • 461
  • 1
  • 8
  • 20