php - 错误:错误的 mysql 库版本或未找到库(使用自定义构建的 MySQL 8 构建 PHP 7 时)
问题描述
错误信息:
configure: error: wrong mysql library version or lib not found. Check config.log for more information.
The command '/bin/sh -c ./configure --prefix=/usr/local/php/install --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php-7.3.2/ --enable-libgcc --with-mysqli=/usr/local/mysql/install/bin/mysql_config --with-pdo-mysql=/usr/local/mysql/install/ --with-zlib-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --with-gd=/usr/local --with-freetype-dir=/usr --enable-ftp --enable-xml --enable-zip --with-bz2 --enable-wddx --without-pear --enable-mbstring --with-openssl --with-curl --enable-intl && make && make install && make clean' returned a non-zero code: 1
由 Dockerfile 中的 configure 命令给出:
# Installing php
WORKDIR /usr/local/include
RUN ln -s /usr/include/x86_64-linux-gnu/curl curl
RUN apt-get update \
&& apt-get install -y \
libxml2-dev libxslt-dev \
libicu-dev \
pkg-config \
libcurl4-gnutls-dev \
re2c libzip-dev
WORKDIR /usr/local/
COPY php-7.3.2.tar.gz /usr/local/
RUN gzip -d php-7.3.2.tar.gz \
&& tar -xvf php-7.3.2.tar \
&& ln -s php-7.3.2 php
WORKDIR /usr/local/php/
RUN ./configure \
--prefix=/usr/local/php/install \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-config-file-path=/usr/local/php-7.3.2/ \
--enable-libgcc \
--with-mysqli=/usr/local/mysql/install/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql/install/ \
--with-zlib-dir=/usr \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-gd=/usr/local \
--with-freetype-dir=/usr \
--enable-ftp \
--enable-xml \
--enable-zip \
--with-bz2 \
--enable-wddx \
--without-pear \
--enable-mbstring \
--with-openssl \
--with-curl \
--enable-intl \
&& make \
&& make install \
&& make clean
之前,使用 Dockerfile 成功安装了 MySQL 服务器:
FROM stephaneeybert/ubuntuos:18.04
# Installing the mysql client
RUN apt-get install -y libncurses-dev
COPY mysql-8.0.15.tar.gz /usr/local/
WORKDIR /usr/local
RUN gzip -d mysql-8.0.15.tar.gz \
&& tar -xvf mysql-8.0.15.tar \
&& mv mysql-8.0.15 mysql-source
RUN mkdir mysql
WORKDIR /usr/local/mysql/
RUN mkdir install \
&& mkdir install/data \
&& mkdir install/var \
&& mkdir install/etc \
&& mkdir install/tmp
WORKDIR /usr/local/mysql/
RUN cmake -- -j4 \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/install \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITHOUT_TOKUDB=1 \
-DMYSQL_DATADIR=/usr/local/mysql/install/data \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/mysql/install/boost \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/install/tmp/mysql.sock \
/usr/local/mysql-source/ \
&& make \
&& make install \
&& make clean
该config.log
文件有这样的说法:
configure:51849: checking for MySQLi support
configure:51885: result: yes
configure:51894: checking whether to enable embedded MySQLi support
configure:51908: result: no
configure:51917: checking for specified location of the MySQL UNIX socket
configure:51932: result: no
configure:52066: checking for mysql_set_server_option in -lmysqlclient_r
configure:52091: cc -o conftest -I/usr/include -g -O2 -fvisibility=hidden -pthread -D_REENTRANT -Wl,-rpath,/usr/local/mysql/install/lib -L/usr/local/mysql/install/lib -L/usr/lib -Wl,-rpath,/usr/lib/gcc/x86_64-linux-gnu/7 -L/usr/lib/gcc/x86_64-linux-gnu/7 -Wl,-rpath,/usr/local/lib -L/usr/local/lib -Wl,-rpath,/usr/lib/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lm -lrt -lssl -lcrypto -ldl conftest.c -lmysqlclient_r -lstdc++ -lgd -lpng -lz -ljpeg -lpng -lz -ljpeg -lbz2 -lz -lrt -lm -ldl -lnsl -lpthread -lgcc -lxml2 -lssl -lcrypto -lcurl -lxml2 -lssl -lcrypto -lfreetype -lfreetype -licui18n -licuuc -licudata -licuio >&5
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: error: ld returned 1 exit status
确实,目录中没有mysqlclient_r
文件lib
:
root@7d84572cf230:/usr/local/php# ll /usr/local/mysql/install/lib
total 78904
drwxr-xr-x 5 root root 4096 Feb 10 16:21 ./
drwxrwxr-x 17 root root 4096 Feb 10 16:21 ../
-rw-r--r-- 1 root root 25593504 Feb 10 10:28 libmysqlclient.a
lrwxrwxrwx 1 root root 20 Feb 10 16:19 libmysqlclient.so -> libmysqlclient.so.21
lrwxrwxrwx 1 root root 25 Feb 10 16:19 libmysqlclient.so.21 -> libmysqlclient.so.21.0.15
-rw-r--r-- 1 root root 11087808 Feb 10 10:28 libmysqlclient.so.21.0.15
-rw-r--r-- 1 root root 18383678 Feb 10 16:07 libmysqlharness.a
lrwxrwxrwx 1 root root 20 Feb 10 16:21 libmysqlharness.so -> libmysqlharness.so.1
-rw-r--r-- 1 root root 7750224 Feb 10 16:09 libmysqlharness.so.1
lrwxrwxrwx 1 root root 19 Feb 10 16:21 libmysqlrouter.so -> libmysqlrouter.so.1
-rw-r--r-- 1 root root 17906048 Feb 10 16:11 libmysqlrouter.so.1
-rw-r--r-- 1 root root 43678 Feb 10 10:30 libmysqlservices.a
drwxr-xr-x 2 root root 4096 Feb 10 16:21 mysqlrouter/
drwxr-xr-x 2 root root 4096 Feb 10 16:19 pkgconfig/
drwxr-xr-x 3 root root 4096 Feb 10 16:19 plugin/
解决方案
将符号链接添加到丢失的库文件后,该configure
命令可以正常完成:
RUN ln -s /usr/local/mysql/install/lib/libmysqlclient.a /usr/local/mysql/install/lib/libmysqlclient_r.a
但是该make
命令稍后会失败,缺少 mysql 库。
mysqlnd
但是,如果使用在 configure 命令中调用的 MySQL 的 PHP 本机驱动程序,则该make
命令成功:
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
推荐阅读
- api - 无法从 Laminas API 工具中的管理 UI 创建新 API
- drake - Autodiff 清除渐变
- c++ - 使用 makefile 构建和运行时出现“运行时错误 2”
- javascript - 尝试更新 Firebase 实时数据库时出错
- python - Python - 用 docx 中的图像替换字符串
- influxdb - InfluxDB InfluxQL - 多次比较同一列
- powershell - 如何在非交互模式下运行 Powershell 脚本(包含参数和选项)
- java - ORDER BY 与 group by (hsqldb) 不能正常工作
- python - 将 Vispy SceneCanvas 嵌入 PyQt5 时,绘图出现在错误的位置
- java - 仅在位图画布android java的选定区域中绘制路径