OneinStack php 7.3.12 升级 php 7.4.0

OneinStack 自带 php 升级脚本,不过目前并不支持从 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.3.12

System => Linux cyhour.com 5.3.11-1.el7.elrepo.x86_64 #1 SMP Tue Nov 12 14:45:59 EST 2019 x86_64
Build Date => Nov 28 2019 15:03:18
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-dir' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--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' '--with-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'
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-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --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 --with-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

要注意,php 7.4.0 已经不支持 --with-gd,得改成 --enable-gd,否则会报错「GD Library Error: imagecreatetruecolor does not exist - please contact your webhost and ask them to install the GD library」。另外还有这几个参数也有变动:configure: WARNING: unrecognized options: --with-freetype-dir, --with-jpeg-dir, --with-png-dir, --with-libxml-dir, --enable-zip, --without-libzip

修改后参数:

./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

下载 PHP

https://www.php.net/downloads.php 页面下载最新 php Stable 版本,解压,进入源码目录。

wget https://www.php.net/distributions/php-7.4.0.tar.gz
tar xf php-7.4.0.tar.gz 
cd php-7.4.0

配置 php

编译前,进入源代码目录,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

可能会报错:No package 'sqlite3' found,解决方法:

yum install libsqlite3x-devel -y

报错:No package 'oniguruma' found,解决方法:

yum install oniguruma-devel -y

实际配置中还出现了:No package 'libsodium' found 错误,重新安装 libsodium,错误依旧。解决方法:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH

或者直接把用不到的 --with-sodium=/usr/local 去掉。

配置成功:

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-zip, --without-libzip

编译 PHP

./configure 配置通过,使用 make 直接编译,会报错:

collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

加上 ZEND_EXTRA_LIBS='-liconv' 即可:

make ZEND_EXTRA_LIBS='-liconv'

安装 PHP

编译成功,先停止 php-fpm 服务:

systemctl stop php-fpm

安装:

make install

安装成功,启动 php-fpm 服务:

systemctl start php-fpm

重新安装上 Memcached

如果原本开启了 Memcached,可能需要重新安装一下,否则网站 500……OneinStack 安装 php-memcached 扩展:

cd /root/oneinstack
./install.sh --php_extensions memcached

参考资料

编译升级PHP 7.4.0

折腾挺累的,还是一键脚本升级方便啊。

--- 完 ---

免责声明:本博客(https://cyhour.com/)仅为分享信息绝非推荐,网站不参与交易绝非中介,内容均仅代表个人观点绝非权威,所有信息仅供参考,读者请自行考虑后入手并自担风险!一分钱一分货仍是恒久不变之真理,未成年读者(包括生理和心理)请在监护人陪同下访问本站!
除非注明,沙唐桔文章均为原创,本文地址 https://cyhour.com/1229/AMP 移动加速版本)转载时必须以链接形式注明原始出处。
Vultr 送$100,搬瓦工年付最低$49,优惠码 BWH3HYATVBJW,更多推荐VPS信息,或支持老杨
Views: 1.1K Tags:  ,  , 

Comments:12

  1. 还是习惯面板操作。。。。。宝塔,我离不了了。

    2019.12.10 13:15 # 回复
    1楼
  2. PHP7.4 有啥特性

    2019.12.10 17:34 # 回复
    2楼
  3. 升级了有什么感受。

    2019.12.12 00:50 # 回复
    3楼
  4. TZH

    oneinstack 那个升级脚本一直只能在小版本内更新,不能跨大版本,不过好像更新也很简单,直接删除再用 Oneinstack 重装一次 PHP 7.4 就好,其他不用安装,理论上是行得通的。

    2020.01.02 09:41 # 回复
    4楼
    • @TZH 也是个方法,下次有需要试试。现在以及按文中方法折腾升级上去了。

      2020.01.02 09:48 # 回复

发表留言

Vultr 送$100,搬瓦工年付最低$49,优惠码 BWH3HYATVBJW,更多推荐VPS信息