2020-11-26,PHP 8.0.0 正式版发布,WordPress 5.6 昨天出来了,开始支持 PHP 8,今天看到博友说 1G 内存也能跑 PHP7、PHP8 共存,忍不住在探针站试着升级了一下。
OneinStack 自带 php 升级脚本,不过并不支持跨版本升级,比如无法从 php 7.4.12 升级到 php 8.0.0,参考「OneinStack php 7.3.12 升级 php 7.4.0」方法手动升级,还挺顺利,看起来没什么问题。
温馨提示:折腾前先备份一下!!!或者做个快照!!!
备份当前版本 php
which php ## 一般是 /usr/local/php/bin/php
cp -r /usr/local/php /usr/local/php_bak
获取当前版本 php 配置参数
执行如下命令:
/usr/local/php/bin/php -i | head
输出配置参数:
phpinfo()
PHP Version => 7.4.12
System => Linux cyhour.com 5.9.1-1.el7.elrepo.x86_64 #1 SMP Fri Oct 16 10:55:30 EDT 2020 x86_64
Build Date => Nov 20 2020 23:07:42
Configure Command => './configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--with-config-file-scan-dir=/usr/local/php/etc/php.d' '--with-fpm-user=www' '--with-fpm-group=www' '--enable-fpm' '--enable-opcache' '--disable-fileinfo' '--enable-mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir=/usr/local' '--with-freetype' '--with-jpeg' '--with-zlib' '--with-libxml' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-exif' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl=/usr/local/curl' '--enable-mbregex' '--enable-mbstring' '--with-password-argon2' '--with-sodium=/usr/local' '--enable-gd' '--with-openssl=/usr/local/openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-ftp' '--enable-intl' '--with-xsl' '--with-gettext' '--enable-zip' '--without-libzip' '--enable-soap' '--disable-debug' 'PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:'
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /usr/local/php/etc
Loaded Configuration File => /usr/local/php/etc/php.ini
./configure 后面就是需要的参数:
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-fpm-user=www --with-fpm-group=www --enable-fpm --enable-opcache --disable-fileinfo --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local --with-freetype --with-jpeg --with-zlib --with-libxml --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/curl --enable-mbregex --enable-mbstring --with-password-argon2 --with-sodium=/usr/local --enable-gd --with-openssl=/usr/local/openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --enable-intl --with-xsl --with-gettext --enable-zip --without-libzip --enable-soap --disable-debug PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:
下载 PHP
从 https://www.php.net/downloads.php 页面下载最新 php Stable 版本,解压,进入源码目录。
wget https://www.php.net/distributions/php-8.0.0.tar.gz
tar xf php-8.0.0.tar.gz
cd php-8.0.0
可能需要的安装包(依赖):
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel pcre-devel sqlite-devel unzip autoconf m4 gcc gcc-c++ mhash-devel libtool-ltdl libtool-ltdl-devel oniguruma oniguruma-devel
配置 php
编译前,进入源代码目录(如:/root/oneinstack/src/php-8.0.0),configure 脚本配置。
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-fpm-user=www --with-fpm-group=www --enable-fpm --enable-opcache --disable-fileinfo --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local --with-freetype --with-jpeg --with-zlib --with-libxml --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/curl --enable-mbregex --enable-mbstring --with-password-argon2 --with-sodium=/usr/local --enable-gd --with-openssl=/usr/local/openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --enable-intl --with-xsl --with-gettext --enable-zip --without-libzip --enable-soap --disable-debug PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:
error: iconv does not support errno
可能报错:configure: error: iconv does not support errno,解决方法:1.15、1.16 报错可以尝试 1.14 版本 libiconv:
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
./configure --prefix=/usr/local/libiconv
make && make install
或者使用 1.15、1.16 版本,将 --with-iconv-dir=/usr/local/libiconv 改成 --with-iconv=/usr/local/libiconv
No package 'libzip' found 或者 Requested 'libzip >= 0.11' but version of libzip is 0.10.1
还可能会报错:No package 'libzip' found 或者 Requested 'libzip >= 0.11' but version of libzip is 0.10.1
没有找到 libzip 库或者找到了但是版本低于 0.11,yum 安装 libzip-devel,安装的版本是 0.10,版本达不到要求。所以,需要卸载掉 yum 安装的 libzip 然后手动安装新版。
查看是否有安装过 libzip
rpm -q libzip && rpm -q libzip-devel
yum remove libzip-devel libzip ##如果有,卸载
从官网下载并编译安装 libzip
wget https://libzip.org/download/libzip-1.3.2.tar.gz
tar zxf libzip-1.3.2.tar.gz
cd libzip-1.3.2
./configure
make && make install
如果是下载 libzip 1.5.* 以上版本,则需要采用如下安装方式:
yum -y install cmake
wget https://libzip.org/download/libzip-1.5.2.tar.gz
tar zxf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ..
make && make install
查看 libzip 安装位置
whereis libzip
一般位置:
libzip: /usr/local/lib/libzip.la /usr/local/lib/libzip.a /usr/local/lib/libzip.so
动态链接库添加为系统共享
echo "/usr/local/lib" >>/etc/ld.so.conf
ldconfig -v | grep libzip
echo $PKG_CONFIG_PATH ##检查 $PKG_CONFIG_PATH 路径
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH
安装完再进入 php8 源码目录执行前面的 ./configure 进行配置
配置成功
Generating files
configure: patching main/php_config.h.in
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
configure: WARNING: unrecognized options: --enable-inline-optimization, --with-xmlrpc
有 WARNING: unrecognized options: --enable-inline-optimization, --with-xmlrpc,不过看着应该没什么问题,就继续编译了。
编译 PHP
./configure 配置通过,使用 make 直接编译。
make
安装 PHP
Build complete.
Don't forget to run 'make test'.
编译成功,先停止 php-fpm 服务:
systemctl stop php-fpm
安装:
make install
日志:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20200930/
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/php/php/man/man1/
Installing PHP FPM binary: /usr/local/php/sbin/
Installing PHP FPM defconfig: skipping
Installing PHP FPM man page: /usr/local/php/php/man/man8/
Installing PHP FPM status page: /usr/local/php/php/php/fpm/
Installing phpdbg binary: /usr/local/php/bin/
Installing phpdbg man page: /usr/local/php/php/man/man1/
Installing PHP CGI binary: /usr/local/php/bin/
Installing PHP CGI man page: /usr/local/php/php/man/man1/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
/root/oneinstack/src/php-8.0.0/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin/phar.phar
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
安装成功,启动 php-fpm 服务:
systemctl start php-fpm
这时候访问网站发现后台可以正常进去,但是首页 404 了……想起 WordPress 还是 5.5.3,进去升级了一下,访问正常了。
重新安装上 Memcached
如果原本开启了 Memcached,可能需要重新安装一下,否则网站 500……OneinStack 安装 php-memcached 扩展:
cd /root/oneinstack
./install.sh --php_extensions memcached
开启 fileinfo 扩展?
fileinfo 已集成至 php 项目源代码内(https://pecl.php.net/package/Fileinfo)
正常情况下,OneinStack 可以使用以下命令快速开启 fileinfo 扩展:
cd /root/oneinstack
./install.sh --php_extensions fileinfo
不过,如无意外,是开启不了的(CentOS 7 系统 php8 开启 fileinfo 失败):
/root/oneinstack/src/php-8.0.0/ext/fileinfo/libmagic/funcs.c: In function ‘file_checkfmt’:
/root/oneinstack/src/php-8.0.0/ext/fileinfo/libmagic/funcs.c:97:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (const char *p = fmt; *p; p++) {
^
/root/oneinstack/src/php-8.0.0/ext/fileinfo/libmagic/funcs.c:97:2: note: use option -std=c99 or -std=gnu99 to compile your code
make: *** [libmagic/funcs.lo] Error 1
PHP fileinfo module install failed, Please contact the author!
看样子是 GCC 与 C99 的问题,网友给出了解决办法:修改 Makefile 文件,加上 -std=c99 参数。
方法:
cd /root/oneinstack/src
wget https://www.php.net/distributions/php-8.0.0.tar.gz
tar xf php-8.0.0.tar.gz
cd php-8.0.0/ext/fileinfo
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-fileinfo
至此会在 /root/oneinstack/src/php-8.0.0/ext/fileinfo 目录下生成 Makefile 文件,打开,在 25 行 CFLAGS = -g -O2 处加上 -std=c99 参数,修改后:CFLAGS = -std=c99 -g -O2
修改完成再 make 应该就可以了:
make
make install
开启成功会有类似提示:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20200930/
瓦工貌似不支持热备份/快照,博客暂时不升级,怕出问题有得折腾。
--- 完 ---
唉 折腾永无止境?
@灰常记忆 不断升级嘛~
还在用5的路过
@哥斯拉 php 5?
php 7 值得拥有。
版本已经够高了,不过还是不影响对最高版本的追求。
@郑永 7快停止支持了啊。
暂时先用7.4
@流金岁月 嗯,同 7.4……试试没问题再升级。