Ubuntu16.04 升级到 18.04

Posted by cj on December 21, 2021

根据 ppa的声明

Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don’t ask for end-of-life PHP versions or Ubuntu release, they won’t be provided.

要了半条老命。。。

没办法,生产环境是 Ubuntu16.04 + php7.2,升级 Ubutnu 大版本风险太大,我这个开发客串的运维也只能赶鸭子上架,升级到 php8.0 也只能手动来了。

一、PHP8编译

按照 这篇教程

STEP 1: sudo apt-get install autoconf build-essential curl libtool
libssl-dev libcurl4-openssl-dev libxml2-dev libreadline7
libreadline-dev libzip-dev libzip4 nginx openssl
pkg-config zlib1g-dev

其中 Ubuntu 16.04 没有 libreadline7 这个包,以 libreadline6 替换。

提示:

The following packages have unmet dependencies:
 libxml2-dev : Depends: libxml2 (= 2.9.3+dfsg1-1ubuntu0.7) but 2.9.9+dfsg-1+ubuntu16.04.1+deb.sury.org+2 is to be installed
E: Unable to correct problems, you have held broken packages.

好吧,继续源码编译。

  1. libxml2
wget http://security.debian.org/debian-security/pool/updates/main/libx/libxml2/libxml2_2.9.4+dfsg1.orig.tar.xz
tar xvJf libxml2_2.9.4+dfsg1.orig.tar.xz
cd libxml2_2.9.4
./autogen
make
make install

继续 apt install 检查一下,提示:

The following packages have unmet dependencies:
 libzip-dev : Depends: libzip4 (= 1.0.1-0ubuntu1) but 1.7.3-1+ubuntu16.04.1+deb.sury.org+2 is to be installed
E: Unable to correct problems, you have held broken packages.
  1. 继续下载编译 libzip:
wget https://libzip.org/download/libzip-1.8.0.tar.xz
tar xvJf libzip-1.8.0.tar.xz
cd libzip-1.8.0
mkdir build && cd build
cmake ..

提示:

-- Could NOT find MbedTLS (missing: MbedTLS_LIBRARY MbedTLS_INCLUDE_DIR) (Required is at least version "1.0")
-- Could NOT find LibLZMA: Found unsuitable version "5.1.0", but required is at least "5.2" (found /usr/lib/x86_64-linux-gnu/liblzma.so)
CMake Warning at CMakeLists.txt:194 (message):
  -- lzma library not found; lzma/xz support disabled
-- Could NOT find Zstd (missing: Zstd_LIBRARY Zstd_INCLUDE_DIR)
CMake Warning at CMakeLists.txt:203 (message):
  -- zstd library not found; zstandard support disabled
  1. 缺少 MbedTLS, apt install libmbedtls-dev

  2. xz-utils版本过低,继续下载编译:

wget https://tukaani.org/xz/xz-5.2.5.tar.xz
tar vxJf xz-5.2.5.tar.xz
cd xz-5.2.5
./autogen.sh

提示:./autogen.sh: 15: ./autogen.sh: autopoint: not foundapt install autopoint 安装一下继续:

./autogen.sh
./configure
make 
make install
  1. 缺少 zstd, apt install libzstd1-dev

  2. 继续编译 libzip

删除 build 后重新 cmake,这次没问题了。 make 一下,提示:

../lib/libzip.so.5.4: undefined reference to `ZSTD_minCLevel'
collect2: error: ld returned 1 exit status
src/CMakeFiles/zipmerge.dir/build.make:95: recipe for target 'src/zipmerge' failed
make[2]: *** [src/zipmerge] Error 1
CMakeFiles/Makefile2:362: recipe for target 'src/CMakeFiles/zipmerge.dir/all' failed
make[1]: *** [src/CMakeFiles/zipmerge.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

搞不下去了。。。陷入了 dependency hell

二、还是升级到 18.04吧。。。

创建快照,开始升级。

还算顺利,一路安装 php8.0、修改配置、更新代码不提,关键 grpc 模块使用 /usr/bin/phpize8.0 && ./configure && make && make install 后仍然是2017版本的,php8用不了。懒得同步 grpc 源码了,直接 apt install php8.0-grpc && systemctl reload php8.0-fpm.service 搞定。

后记

ubuntu 停止支持 16.04,php 停止支持 7.2, ppa 那里直接跟着废弃了。今年5月份其他机器还能 apt install php8.0,结果被其他事耽搁着一直没更新,拖到现在更麻烦了。

还是得时常关注服务器端工具链的更新啊!