编译安装PHP8和Swoole4

PHP8在6月25号发布了alpha1版本,JIT是大家最为关心的一个功能

鸟哥也亲自下场写了一篇《PHP8新特性之JIT简介》,感兴趣的同学可以去看看。

很多使用Swoole的同学都想在PHP8中体验一下性能,奈何编译不过…这篇文章我们就来编译一下PHP8和Swoole4。

PHP8

首先获取PHP8-alpha1的源码,由于码云暂时关闭了 mirros 仓库的下载通道,我们就直接从PHP官网下载吧,解压并进入对应目录

wget https://downloads.php.net/~pollita/php-8.0.0alpha1.tar.gz

tar -zxvf php-8.0.0alpha1.tar.gz

cd php-8.0.0alpha1/

然后我们就可以配置编译参数来进行编译了,至于配置参数的变更、弃用这里就跳过了

./configure --prefix=/usr/local/php8 --enable-opcache --with-config-file-path=/usr/local/php8/etc --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm --enable-static --enable-sockets --with-zip --enable-calendar --enable-bcmath --enable-mbstring --with-zlib --with-iconv=/usr/local/libiconv --enable-gd --enable-mbstring --with-curl --with-freetype --with-mysql-sock=/tmp/mysql.sock --disable-ipv6 --disable-debug --with-openssl --enable-intl

在执行中可能会遇到一些问题,这里简单说明一下:

1. configure: error: iconv does not support errno

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
./configure --prefix=/usr/local/libiconv
make && make install

2. No package ‘oniguruma’ found

yum install oniguruma-devel

3. No package ‘libzip’ found或者Requested ‘libzip >= 0.11’ but version of libzip is 0.10.1

checking for libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0... no
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:

Requested 'libzip >= 0.11' but version of libzip is 0.10.1

这个报错提示非常明显,配置程序没有找到libzip库或者找到了但是版本低于0.11,你用yum安装libzip-devel的话,安装的版本是0.10,版本达不到要求。所以,我们需要卸载掉yum安装的libzip然后手动安装新版。

yum remove libzip libzip-devel

wget https://libzip.org/download/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install

这个时候还需要让PHP的configure程序知道你安装的libzip在哪里,刚才安装libzip是在/usr/local/lib,可以使用ls -l /usr/local/lib查看目录,就可以看到libzip.so libzip.so.5 libzip.so.5.0.0 还有一个pkgconfig目录,然后我们再在configure的会话窗口直接输入:

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"

再次执行文章开头的./configure ...就会很顺利的看到Thank you for using PHP.
然后执行make && make install等待安装成功,安装完成后执行命令查看版本信息

$ /usr/local/php8/bin/php -v
PHP 8.0.0alpha1 (cli) (built: Jun 28 2020 17:27:11) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies

复制php.ini配置文件

cp php.ini-production /usr/local/php8/etc/php.ini

因为PHP8的JIT是在Opcache之中提供的,所以我们还需要修改配置文件加上zend_extension=opcache.so

Swoole4

Swoole目前已经在master分支支持了PHP8,由于还没有发布版本,所以有些同学使用v4.5.2编译时会出错,这里直接使用master分支代码进行编译

git clone [email protected]:swoole/swoole-src.git --depth=1
/usr/local/php8/bin/phpize
./configure --enable-openssl --enable-sockets --enable-mysqlnd --enable-http2 --with-php-config=/usr/local/php8/bin/php-config
make
make install

编译完成后修改php.ini加入extension=swoole.so
执行php -m查看安装的扩展

$ /usr/local/php8/bin/php -m
[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
fileinfo
filter
gd
hash
iconv
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
sockets
SPL
sqlite3
standard
swoole
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

执行php --ri swoole查看swoole扩展版本

$ /usr/local/php8/bin/php --ri swoole

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.5.3-alpha
Built => Jun 28 2020 17:46:50
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.0.2k-fips  26 Jan 2017
http2 => enabled
pcre => enabled
zlib => 1.2.7
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608

大家现在就可以去体验PHP8+Swoole了

7 条评论

发表评论

*