如何解决Laravel实时服务器上的此错误? [英] How to solve this error on live server for laravel?
问题描述
我已经在本地成功安装了此软件包composer require spatie/laravel-image-optimizer
,但是当我尝试在实时服务器上安装时,出现了此错误
I have installed this package success locally composer require spatie/laravel-image-optimizer
, but when I tried to install on the live server I got this errors
no@zz607:/var/www/html$ composer require spatie/laravel-image-
optimizer
Using version ^1.4 for spatie/laravel-image-optimizer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
mmap() failed: [12] Cannot allocate memory
mmap() failed: [12] Cannot allocate memory
mmap() failed: [12] Cannot allocate memory
PHP Fatal error: Out of memory (allocated 544395264) (tried to
allocate 20480 bytes) in
/usr/share/php/Composer/Repository/ComposerRepository.php on line 321
Fatal error: Out of memory (allocated 544395264) (tried to allocate
20480 bytes) in
/usr/share/php/Composer/Repository/ComposerRepository.php on line 321
服务器信息
推荐答案
您的问题与可能只有1gb RAM且没有内存交换的事实有关,因此让我们创建它并使它在运行时腾出一些时间.作曲者执行时间.
Your problem is related to the probable fact of having only 1gb of RAM and not having memory swap, so let's create and enable it to take some time off at the time of composer execution.
请按照以下步骤操作:
1)创建 1gb 内存交换文件:
$ sudo fallocate -l 1G /swapfile
$ sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
此命令创建了大小为1GB的
/swapfile
文件.
2)配置要交换的文件:
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
3):启用交换:
$ sudo swapon /swapfile
要查看结果,可以运行free -m
或在htop
To see result you can run free -m
or see on htop
示例:$ sudo free -m
Example: $ sudo free -m
total usada livre compart. buff/cache disponível
Mem.: 7664 1052 3436 56 3175 6259
Swap: 1024 0 1024
示例:$ sudo swapon --show
Example: $ sudo swapon --show
NAME TYPE SIZE USED PRIO
/swapfile file 1G 0B -2
请测试.
这篇关于如何解决Laravel实时服务器上的此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!