记一次php安装失败的解决过程

起因

近期买了个新域名:屑.cc,一开始挂到了我在腾讯云的主服务器上,不过因为没备案,导致被腾讯云阻断。因为用的是tls加密,所以是直接重置链接,没有任何提示。

于是乎我想起了我那台搬瓦工的机器,挂在那里应该可以。当我尝试在宝塔面板后台安装php,他却报错了,显示如下:

checking for the location of libpng... yes
checking for the location of libXpm... no
checking for FreeType 2... /usr/local/freetype
checking whether to enable JIS-mapped Japanese font support in GD... no
configure: error: webp/decode.h not found.
make: *** No targets specified and no makefile found.  Stop.
make: *** No rule to make target 'install'.  Stop.
========================================================
Ubuntu 16.04.2 LTS 
 \l
Bit:64 Mem:503M Core:1 gcc:5.4.0 cmake:3.5.1
Linux ban-cn2.papapoi.com 4.4.0-177-generic #207-Ubuntu SMP Mon Mar 16 01:16:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
ERROR: php-7.3.17 install failed.
安装失败,请截图以上报错信息发帖至论坛www.bt.cn/bbs求助

初步尝试

一开始觉得很简单,不就少个库嘛,那装一下就好了

sudo apt-get install libwebp-dev

结果返回了个报错

root@ban-cn2:~# apt install libwebp-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 libwebp-dev : Depends: libwebpdemux1 (= 0.4.4-1) but it is not going to be installed
 linux-image-generic : Depends: linux-image-4.4.0-178-generic but it is not going to be installed or
                                linux-image-unsigned-4.4.0-178-generic but it is not going to be installed
                       Recommends: thermald but it is not going to be installed
 linux-modules-extra-4.4.0-178-generic : Depends: linux-image-4.4.0-178-generic but it is not going to be installed or
                                                  linux-image-unsigned-4.4.0-178-generic but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

尝试修复内核

这报错应该就是某次更新内核到一半停了?那修复下就好了嘛:

sudo apt --fix-broken install

结果又来了个报错

root@ban-cn2:~# apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-169 linux-headers-4.4.0-169-generic linux-headers-4.4.0-170
  linux-headers-4.4.0-170-generic linux-headers-4.4.0-171 linux-headers-4.4.0-171-generic
  linux-headers-4.4.0-173 linux-headers-4.4.0-173-generic linux-headers-4.4.0-62
  linux-headers-4.4.0-62-generic linux-image-4.4.0-169-generic linux-image-4.4.0-170-generic
  linux-image-4.4.0-171-generic linux-image-4.4.0-173-generic linux-image-4.4.0-62-generic
  linux-image-extra-4.4.0-62-generic linux-modules-4.4.0-169-generic linux-modules-4.4.0-170-generic
  linux-modules-4.4.0-171-generic linux-modules-4.4.0-173-generic linux-modules-extra-4.4.0-169-generic
  linux-modules-extra-4.4.0-170-generic linux-modules-extra-4.4.0-171-generic
  linux-modules-extra-4.4.0-173-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  linux-image-4.4.0-178-generic linux-modules-4.4.0-178-generic
Suggested packages:
  fdutils linux-doc-4.4.0 | linux-source-4.4.0 linux-tools
The following NEW packages will be installed:
  linux-image-4.4.0-178-generic linux-modules-4.4.0-178-generic
0 upgraded, 2 newly installed, 0 to remove and 126 not upgraded.
7 not fully installed or removed.
Need to get 0 B/18.9 MB of archives.
After this operation, 67.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 308268 files and directories currently installed.)
Preparing to unpack .../linux-modules-4.4.0-178-generic_4.4.0-178.208_amd64.deb ...
Unpacking linux-modules-4.4.0-178-generic (4.4.0-178.208) ...
dpkg: error processing archive /var/cache/apt/archives/linux-modules-4.4.0-178-generic_4.4.0-178.208_amd64.deb (--unpack):
 cannot copy extracted data for './boot/System.map-4.4.0-178-generic' to '/boot/System.map-4.4.0-178-generic.dpkg-new': failed to write (No space left on device)
No apport report written because the error message indicates a disk full error
                                                                              dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Preparing to unpack .../linux-image-4.4.0-178-generic_4.4.0-178.208_amd64.deb ...
Unpacking linux-image-4.4.0-178-generic (4.4.0-178.208) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-4.4.0-178-generic_4.4.0-178.208_amd64.deb (--unpack):
 cannot copy extracted data for './boot/vmlinuz-4.4.0-178-generic' to '/boot/vmlinuz-4.4.0-178-generic.dpkg-new': failed to write (No space left on device)
No apport report written because the error message indicates a disk full error
                                                                              dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/linux-modules-4.4.0-178-generic_4.4.0-178.208_amd64.deb
 /var/cache/apt/archives/linux-image-4.4.0-178-generic_4.4.0-178.208_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

清理垃圾

上面提示空间不足,那就看看有多少剩余空间吧

root@ban-cn2:~# df -lh
Filesystem      Size  Used Avail Use% Mounted on
udev            231M     0  231M   0% /dev
tmpfs            51M  8.4M   43M  17% /run
/dev/sda2       9.5G  6.8G  2.2G  77% /
tmpfs           252M  828K  252M   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           252M     0  252M   0% /sys/fs/cgroup
/dev/sda1       361M  359M     0 100% /boot
tmpfs            51M     0   51M   0% /run/user/0

好家伙,/boot下面都没地方了,看看有什么文件占地方吧

root@ban-cn2:~# cd /boot/
root@ban-cn2:/boot# ls
abi-4.4.0-62-generic          initrd.img-4.4.0-171-generic  System.map-4.4.0-177-generic
config-4.4.0-169-generic      initrd.img-4.4.0-173-generic  System.map-4.4.0-62-generic
config-4.4.0-170-generic      initrd.img-4.4.0-174-generic  vmlinuz-4.4.0-169-generic
config-4.4.0-171-generic      initrd.img-4.4.0-177-generic  vmlinuz-4.4.0-170-generic
config-4.4.0-173-generic      initrd.img-4.4.0-62-generic   vmlinuz-4.4.0-171-generic
config-4.4.0-174-generic      lost+found                    vmlinuz-4.4.0-173-generic
config-4.4.0-177-generic      System.map-4.4.0-169-generic  vmlinuz-4.4.0-174-generic
config-4.4.0-62-generic       System.map-4.4.0-170-generic  vmlinuz-4.4.0-177-generic
grub                          System.map-4.4.0-171-generic  vmlinuz-4.4.0-62-generic
initrd.img-4.4.0-169-generic  System.map-4.4.0-173-generic
initrd.img-4.4.0-170-generic  System.map-4.4.0-174-generic

一堆旧版本内核文件。。。。

那就慢慢清理吧。。

先看看当前内核版本,然后把其他的都rm

root@ban-cn2:/boot# uname -a
Linux ban-cn2.papapoi.com 4.4.0-177-generic #207-Ubuntu SMP Mon Mar 16 01:16:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
root@ban-cn2:/boot# rm initrd.img-4.4.0-171-generic
root@ban-cn2:/boot# rm initrd.img-4.4.0-173-generic
root@ban-cn2:/boot# rm initrd.img-4.4.0-174-generic
root@ban-cn2:/boot# rm initrd.img-4.4.0-170-generic
root@ban-cn2:/boot# rm initrd.img-4.4.0-169-generic
#后面的省略。。

清理完后明显正常了许多

root@ban-cn2:/boot# df -lh
Filesystem      Size  Used Avail Use% Mounted on
udev            231M     0  231M   0% /dev
tmpfs            51M  8.4M   43M  17% /run
/dev/sda2       9.5G  6.8G  2.2G  77% /
tmpfs           252M  828K  252M   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           252M     0  252M   0% /sys/fs/cgroup
/dev/sda1       361M   71M  272M  21% /boot
tmpfs            51M     0   51M   0% /run/user/0

重新修复内核

跑命令就完事了

root@ban-cn2:/boot# apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-169 linux-headers-4.4.0-169-generic linux-headers-4.4.0-170
  linux-headers-4.4.0-170-generic linux-headers-4.4.0-171 linux-headers-4.4.0-171-generic
  linux-headers-4.4.0-173 linux-headers-4.4.0-173-generic linux-headers-4.4.0-62
  linux-headers-4.4.0-62-generic linux-image-4.4.0-169-generic linux-image-4.4.0-170-generic
  linux-image-4.4.0-171-generic linux-image-4.4.0-173-generic linux-image-4.4.0-62-generic
  linux-image-extra-4.4.0-62-generic linux-modules-4.4.0-169-generic linux-modules-4.4.0-170-generic
  linux-modules-4.4.0-171-generic linux-modules-4.4.0-173-generic linux-modules-extra-4.4.0-169-generic
  linux-modules-extra-4.4.0-170-generic linux-modules-extra-4.4.0-171-generic
  linux-modules-extra-4.4.0-173-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  linux-image-4.4.0-178-generic linux-modules-4.4.0-178-generic
Suggested packages:
  fdutils linux-doc-4.4.0 | linux-source-4.4.0 linux-tools
The following NEW packages will be installed:
  linux-image-4.4.0-178-generic linux-modules-4.4.0-178-generic
0 upgraded, 2 newly installed, 0 to remove and 126 not upgraded.
7 not fully installed or removed.
Need to get 0 B/18.9 MB of archives.
After this operation, 67.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 308268 files and directories currently installed.)
Preparing to unpack .../linux-modules-4.4.0-178-generic_4.4.0-178.208_amd64.deb ...
Unpacking linux-modules-4.4.0-178-generic (4.4.0-178.208) ...
Preparing to unpack .../linux-image-4.4.0-178-generic_4.4.0-178.208_amd64.deb ...
Unpacking linux-image-4.4.0-178-generic (4.4.0-178.208) ...
Setting up linux-modules-4.4.0-178-generic (4.4.0-178.208) ...
Setting up linux-image-4.4.0-178-generic (4.4.0-178.208) ...
I: /vmlinuz.old is now a symlink to boot/vmlinuz-4.4.0-177-generic
I: /initrd.img.old is now a symlink to boot/initrd.img-4.4.0-177-generic
I: /vmlinuz is now a symlink to boot/vmlinuz-4.4.0-178-generic
I: /initrd.img is now a symlink to boot/initrd.img-4.4.0-178-generic
Setting up linux-modules-extra-4.4.0-178-generic (4.4.0-178.208) ...
Setting up linux-image-generic (4.4.0.178.186) ...
Setting up linux-headers-4.4.0-178 (4.4.0-178.208) ...
Setting up linux-headers-4.4.0-178-generic (4.4.0-178.208) ...
Setting up linux-headers-generic (4.4.0.178.186) ...
Setting up linux-generic (4.4.0.178.186) ...
Setting up linux-libc-dev:amd64 (4.4.0-178.208) ...
Processing triggers for linux-image-4.4.0-178-generic (4.4.0-178.208) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-4.4.0-178-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
/etc/kernel/postinst.d/zz-update-grub:
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-178-generic
Found initrd image: /boot/initrd.img-4.4.0-178-generic
Found linux image: /boot/vmlinuz-4.4.0-177-generic
Found initrd image: /boot/initrd.img-4.4.0-177-generic
Found linux image: /boot/vmlinuz-4.4.0-62-generic
done

又报错

这次报错是编译途中报错了,看看打印:

recipe for target 'Zend/zend_execute.lo' failed

看样子应该是内存不足,那就加1G的swap呗:

dd if=/dev/zero of=/swapfile bs=1024 count=1048576
mkswap /swapfile
swapon /swapfile
chown root:root /swapfile
chmod 0600 /swapfile

继续安装

最后当然装好了

  1750K .......... .......... .......... .......... .......... 93% 7.70M 0s
  1800K .......... .......... .......... .......... .......... 96% 23.2M 0s
  1850K .......... .......... .......... .......... .......... 98% 25.5M 0s
  1900K .......... .......... ...                             100% 10.5M=0.2s

2020-05-03 02:36:07 (11.6 MB/s) - ‘/usr/bin/composer’ saved [1969617/1969617]

Starting php-fpm  done

清理战场

把前面新建的swap文件删了,释放空间,毕竟服务器就只剩2G可用空间了

swapoff /swapfile
rm -rf /swapfile

发表评论

您的电子邮箱地址不会被公开。