编译安装PHP8.0-alpha3

后续

目前发现几个问题:

  1. --with-config-file-scan-dir选项无效,因此无法扫描到/usr/local/etc/php/8.0-alpha/conf.d中的ini文件(在centos7上尝试没有发现这个问题)
  2. 交互式运行无效,/usr/local/opt/php@8.0-alpha/bin/php -a执行后,输出Interactive mode enabled后卡住了,无法输入代码。 (通过指定--with-readline=/usr/local/opt/readline解决)

正文

我写了一系列文章记录我编译安装PHP7.3、PHP7.4的过程,这一次我尝试编译安装PHP8.0,当前PHP8.0处于测试中,请勿直接在您的线上环境使用此版本。

系统信息:MacOS catalina(10.15.5)

# 下载源码
wget https://downloads.php.net/~carusogabriel/php-8.0.0alpha3.tar.bz2

# 解压&切换到目录下
tar -jxvf php-8.0.0alpha3.tar.bz2 && cd php-8.0.0alpha3

# 创建必要的目录
mkdir  /usr/local/opt/php@8.0-alpha
mkdir /usr/local/etc/php/8.0-alpha

# 执行configure
./configure \
  --prefix=/usr/local/opt/php@8.0-alpha \
  --with-config-file-path=/usr/local/etc/php/8.0-alpha \
  --localstatedir=/usr/local/var \
  --sysconfdir=/usr/local/etc/php/8.0-alpha \
  --with-config-file-scan-dir=/usr/local/etc/php/8.0-alpha/conf.d \
  --enable-fpm \
  --with-fpm-user=_www \
  --with-fpm-group=_www \
  --enable-intl \
  --enable-mbstring \
  --enable-pcntl \
  --enable-mysqlnd \
  --with-pdo-mysql \
  --with-readline=/usr/local/opt/readline \
  --without-iconv

报错:

...
checking for iconv... no
checking for libiconv... no
configure: error: Please specify the install prefix of iconv with --with-iconv=<DIR>

根据文档的介绍 https://www.php.net/manual/zh/iconv.installation.php 我认为多一事不如少一事,这个扩展我认为也没啥用,因此加上--without-iconv禁用掉:

继续报错:

...
checking for icu-uc >= 50.1 icu-io icu-i18n... no
configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:

No package 'icu-uc' found
No package 'icu-io' found
No package 'icu-i18n' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ICU_CFLAGS
and ICU_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

这个问题我在编译安装PHP7.4的时候遇到过,解决办法是指定PKG_CONFIG_PATH

执行

cp -r /usr/local/opt/icu4c/lib/pkgconfig/* /usr/local/lib/pkgconfig/
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"

再次执行上面的./configure,最后出现:

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

说明环境检查没问题了,最后make:

make && make install

这个版本的PHP编译速度似乎要快很多!最后出现如下输出:

...
Installing man pages:             /usr/local/opt/php@8.0-alpha/php/man/man1/
  page: phpize.1
  page: php-config.1
/Users/jake/Downloads/php-8.0.0alpha3/build/shtool install -c ext/phar/phar.phar /usr/local/opt/php@8.0-alpha/bin/phar.phar
ln -s -f phar.phar /usr/local/opt/php@8.0-alpha/bin/phar
Installing PDO headers:           /usr/local/opt/php@8.0-alpha/include/php/ext/pdo/

看样子是安装成功了。

尝试一下:

➔ /usr/local/opt/php@8.0-alpha/bin/php -v
PHP 8.0.0alpha3 (cli) (built: Jul 25 2020 15:12:46) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies

复制配置文件:

➔ cp php.ini-development /usr/local/etc/php/8.0-alpha/php.ini
➔ mv /usr/local/etc/php/8.0-alpha/php-fpm.conf.default /usr/local/etc/php/8.0-alpha/php-fpm.conf
➔ mv /usr/local/etc/php/8.0-alpha/php-fpm.d/www.conf.default /usr/local/etc/php/8.0-alpha/php-fpm.d/www.conf

试试php-fpm:

➔ /usr/local/opt/php@8.0-alpha/sbin/php-fpm -t
[25-Jul-2020 18:49:18] ERROR: failed to open configuration file '/usr/local/opt/php@8.0-alpha/etc/php-fpm.conf': No such file or directory (2)
[25-Jul-2020 18:49:18] ERROR: failed to load configuration file '/usr/local/opt/php@8.0-alpha/etc/php-fpm.conf'
[25-Jul-2020 18:49:18] ERROR: FPM initialization failed

这就很奇怪了,明明我指定的目录是/usr/local/etc/php/8.0-alpha,但是却从/usr/local/opt/php@8.0-alpha/etc这个目录里找配置文件了,暂时先手动指定一下:

➔ /usr/local/opt/php@5.6/sbin/php-fpm -y /usr/local/etc/php/8.0-alpha/php-fpm.conf -t
[25-Jul-2020 18:56:19] NOTICE: configuration file /usr/local/etc/php/8.0-alpha/php-fpm.conf test is successful

由于我本地安装了多个php版本,所以我需要修改php-fpm所监听的端口:

# 修改 /usr/local/etc/php/8.0-alpha/php-fpm.d/www.conf
listen = 127.0.0.1:9080

改一下默认的日志文件名,否则启动php-fpm会提示没有日志文件路径:

# 修改 /usr/local/etc/php/8.0-alpha/php-fpm.conf
error_log = /usr/local/var/log/php-fpm@8.0-alpha.log

启动php-fpm:

➔ /usr/local/opt/php@8.0-alpha/sbin/php-fpm -y /usr/local/etc/php/8.0-alpha/php-fpm.conf -D
[25-Jul-2020 19:16:50] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
[25-Jul-2020 19:16:50] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root

Nginx 简单配置:

server {
    listen 80;
    server_name localhost;

    root /usr/local/var/www/localhost;
    index index.php;

    location ~ \.php$ {
        include        fastcgi_params;
        fastcgi_pass   127.0.0.1:9080;
    }
}

创建index.php文件:

# /usr/local/var/www/localhost/index.php
<?php

phpinfo();

访问:

截屏2020-07-25 下午7.33.11

安装结束,如果有什么问题,欢迎您给我反馈!

发表评论

电子邮件地址不会被公开。 必填项已用*标注