文章大纲

php8编译安装报错:undefined reference to `onig_new_match_param'

2022-09-07 20:08:19

今天在Centos7.6系统下编译安装php8.0,报如下错误:

ext/mbstring/.libs/mbstring.o: In function `_php_mb_match_regex':
/root/php-7.4.26/ext/mbstring/mbstring.c:1027: undefined reference to `onig_new_match_param'
/root/php-7.4.26/ext/mbstring/mbstring.c:1029: undefined reference to `onig_initialize_match_param'
/root/php-7.4.26/ext/mbstring/mbstring.c:1031: undefined reference to `onig_set_match_stack_limit_size_of_match_param'
/root/php-7.4.26/ext/mbstring/mbstring.c:1034: undefined reference to `onig_set_retry_limit_in_match_of_match_param'
/root/php-7.4.26/ext/mbstring/mbstring.c:1037: undefined reference to `onig_search_with_param'
/root/php-7.4.26/ext/mbstring/mbstring.c:1040: undefined reference to `onig_free_match_param'
ext/mbstring/.libs/php_mbregex.o: In function `zif_mb_ereg_match':
/root/php-7.4.26/ext/mbstring/php_mbregex.c:1401: undefined reference to `onig_new_match_param'
/root/php-7.4.26/ext/mbstring/php_mbregex.c:1402: undefined reference to `onig_initialize_match_param'
/root/php-7.4.26/ext/mbstring/php_mbregex.c:1410: undefined reference to `onig_match_with_param'
/root/php-7.4.26/ext/mbstring/php_mbregex.c:1411: undefined reference to `onig_free_match_param'
/root/php-7.4.26/ext/mbstring/php_mbregex.c:1407: undefined reference to `onig_set_retry_limit_in_match_of_match_param'
/root/php-7.4.26/ext/mbstring/php_mbregex.c:1404: undefined reference to `onig_set_match_stack_limit_size_of_match_param'
ext/mbstring/.libs/php_mbregex.o: In function `_php_mb_onig_search':
/root/php-7.4.26/ext/mbstring/php_mbregex.c:873: undefined reference to `onig_new_match_param'
/root/php-7.4.26/ext/mbstring/php_mbregex.c:875: undefined reference to `onig_initialize_match_param'
/root/php-7.4.26/ext/mbstring/php_mbregex.c:877: undefined reference to `onig_set_match_stack_limit_size_of_match_param'
/root/php-7.4.26/ext/mbstring/php_mbregex.c:880: undefined reference to `onig_set_retry_limit_in_match_of_match_param'
/root/php-7.4.26/ext/mbstring/php_mbregex.c:883: undefined reference to `onig_search_with_param'
/root/php-7.4.26/ext/mbstring/php_mbregex.c:884: undefined reference to `onig_free_match_param'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] 错误 1


报这个错误的原因,是因为oniguruma安装不正确。

安装php时,会执行如下命令:

./configure \
--prefix=/usr/local/php7 \
--with-config-file-path=/etc \
--with-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-pdo \
--with-pdo-mysql \
--with-gd \
--with-iconv  \
--with-curl \
--with-zlib \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-gd-native-ttf \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--enable-fpm \
--with-bz2
--with-jpeg-dir=/usr/local/jpeg \
--with-freetype-dir \
--with-png-dir=/usr/local/pngp 

其中--enable-mbstring会涉及到一些正则表达式的处理,需要oniguruma插件的支持。


关于oniguruma的安装方式有两种:

第一种:rpm安装oniguruma

yum -y install oniguruma-6.7.0-1.el7.x86_64.rpm
yum -y install oniguruma-devel-6.7.0-1.el7.x86_64.rpm

后面文件是我先下载传到服务器里的。

oniguruma-6.7.0-1.el7.x86_64.rpm

oniguruma-devel-6.7.0-1.el7.x86_64.rpm

这种方式没能解决本文开头的报错。



第二种:源码编译安装oniguruma

wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar -xzvf oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4
./configure --prefix=/usr --libdir=/lib64
make && make install

第一次编译时,没有带上--libdir这部分仍然报错,第二次带上了重新编译,php编译就ok了。


php编译过程:

一开始把依赖都装上,直接执行下面命令

yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++  autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel

然后从这里php下载下载稳定的php版本。这次我下载的是php8.0.23.
后面就是configure、make、make install编译步骤了。

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.


或许由于Centos系统版本原因,上面configure命令好多选项是不存在的。因此除了上面成功提示,还会有如下警告提示:

configure: WARNING: unrecognized options: --with-mysql, --with-gd, --enable-inline-optimization, --enable-gd-native-ttf, --with-xmlrpc, --enable-zipk

mysql在php7中就废弃了(现在用mysqli),很好理解。至于gd为何也不支持了,得另外继续了解了。



make install成功,就会显示配置及脚本各个文件所在的位置,例如如下:

Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-non-zts-20200930/
Installing PHP CLI binary:        /usr/local/php7/bin/
Installing PHP CLI man page:      /usr/local/php7/php/man/man1/
Installing PHP FPM binary:        /usr/local/php7/sbin/
Installing PHP FPM defconfig:     /usr/local/php7/etc/
Installing PHP FPM man page:      /usr/local/php7/php/man/man8/
Installing PHP FPM status page:   /usr/local/php7/php/php/fpm/
Installing phpdbg binary:         /usr/local/php7/bin/
Installing phpdbg man page:       /usr/local/php7/php/man/man1/
Installing PHP CGI binary:        /usr/local/php7/bin/
Installing PHP CGI man page:      /usr/local/php7/php/man/man1/
Installing build environment:     /usr/local/php7/lib/php/build/
Installing header files:          /usr/local/php7/include/php/
Installing helper programs:       /usr/local/php7/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php7/php/man/man1/
  page: phpize.1
  page: php-config.1
/opt/software/php-8.0.23/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin/phar.phar
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/



我要评论
评论列表