PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted

今天在使用composer安装扩展包时报错,如下:

PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///www/server/php/74/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223 Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///www/server/php/74/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223 Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.#

在网上找到的文章如下,

通过上面提示composer链接,输出内存配置信息 php -r "echo ini_get('memory_limit').PHP_EOL;"输出 128M

我尝试修改 php.ini文件,我的路径是 /etc/php7/apache2/php.ini,修改里面的 memory_limit = -1, 重启apache之后,运行 composer update 一样的错误。

我想到的是可能 php 命令和apache2的 php.ini文件不是同一个,所以 wakasann@linux-2ywt:/srv/www/htdocs/sfs> sudo find / -name "php.ini"[sudo] password for root: /etc/php7/cli/php.ini/etc/php7/apache2/php.ini/etc/php7/fastcgi/php.ini

我尝试修改 /etc/php7/cli/php.ini 中的 memory_limit的值为 -1,修改完之后,运行 php -r "echo ini_get('memory_limit').PHP_EOL;"输出结果是: -1 感觉修改成功,composer update也可正常运行了。

可以成功解决,但是不安全,在这里不推荐使用。

终极解决方法

这里写下我的推荐方法,就是使用命令安装。

php -d memory_limit=-1 /usr/bin/composer require xxxx/xxxxxxx

就可以发现安装成功了。

注意

上述命令中的/usr/bin/composer,为composer安装地址
可使用
composer -h
命令进行获取。

你可能感兴趣的:(PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted)