Magento2 – PHP Memory Limit and Setup/Cron Issue

-setupextensionsmagento2

I've done numerous searches and found some people with the same issue but nothing has helped. I'm hosted on GoDaddy's Grow Business hosting and installed Magento 2.2.4 through their cPanel. Everything has been working great. If I pull up phpinfo() I see it has a local memory limit of 756M (the minimum) and a master value of 512M.

Now I'm trying to install an extension through the Web Setup Wizard. When it runs the Readiness check it errors out that memory is only 512M. If I put in debug statements in the PHP readiness check scripts I see that ini_get('memory_limit') is, indeed, 512M. But I can't find ANYTHING in the file system that's doing this. I tried putting a PHP.ini in the /setup folder, no help. I tried putting an ini setting in the .htaccess in the bin/magento folder, no help. Finally, to get around this issue, I simply modified the core PhpReadinessCheck.php (I know, I know, it's temporary). Where it checks if the value is high enough, I just put another block that sets the value, then checks again.

if ($currentMemoryInteger > 0
    && $this->dataSize->convertSizeToBytes($currentMemoryLimit)
       < $this->dataSize->convertSizeToBytes($minimumRequiredMemoryLimit)
) {
    //set to 756M
    ini_set('memory_limit', $minimumRequiredMemoryLimit);
}

Has anyone else run into this issue? Is there a better fix?

Best Answer

For everyone else that is searching for an answer here, I finally found a solution (after 2 full days of troubleshooting and zero luck with technical support).

My phpinfo.php file listed a 2G memory_limit and a master value of 512M but Magento 2 readiness check kept telling me 512 was set.

Setup: Magento 2.2.5, PHP version: 7.0.3

Godaddy Business Hosting (Grow) - This is comparable to a shared hosting service but with allocated resources similar to a VPS server. You cannot modify the master php file but you can add your own .user.ini file to rewrite scripts.

The main issue is that this shared server has the option to select multiple PHP versions (MultiPHP Manager). When you select your version (in this case PHP 7.0), be sure to not to modify any of the "Switch to PHP Options" settings. Adding extensions are fine (you will need to add xsl and zip anyway to use Magento 2). If you modify any of the settings in the "PHP Options" console, it will call these master values every time. Leave them all as default (128M memory_limit, etc). In my case, I modified it to 512M from the default 128M and spent countless hours trying to troubleshoot why it was reading 512M instead of my local 2G value.

Be sure to set up the proper cron jobs to call your local .user.ini file with the correct memory_limit value.

Cron jobs looked like this:

/usr/local/bin/php -c /home/<USERNAME>/public_html/.user.ini /home/<USERNAME>/public_html/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /home/<USERNAME>/public_html/var/log/magento.cron.log

/usr/local/bin/php -c /home/<USERNAME>/public_html/.user.ini /home/<USERNAME>/public_html/update/cron.php >> /home/<USERNAME>/public_html/var/log/update.cron.log

/usr/local/bin/php -c /home/<USERNAME>/public_html/.user.ini /home/<USERNAME>/public_html/bin/magento setup:cron:run >> /home/<USERNAME>/public_html/var/log/setup.cron.log

Notice the local .user.ini file being called after the master php folder instead of the file php -i was telling me to call (/opt/alt/php70/etc/php.ini).

Don't know if these two steps were necessary but I did it anyway:

Flushed cache in ssh

php /home/<USERNAME>/public_html/bin/magento cache:flush

Kill PHP Processes to restart (cPanel > PHP Processes > Kill Processes)

Note - I also updated my .htaccess file to a 2G memory_limit as well just to keep things consistent.

I checked my update.log file and the errors are no more. I also ran a readiness check and it finally passed.

Hope this helps everyone else.

Related Topic