PHP7.0-FPM with Docker:无法加载动态库 OCI8

PHP7.0-FPM with Docker : Unable to load dynamic library OCI8

我用 PHP7.0-FPM 和 Apache 2.4 创建了一个 Docker 图像。我已经安装了 InstantClient 12.2 (basic + sdk) 并且我已经像这样安装了 oci8 :

RUN echo "instantclient,/usr/lib/oracle/12.2/instantclient"| pecl install oci8 && \ echo "extension=oci8.so" > /etc/php/7.0/mods-available/oci8.ini && \ ln -s /etc/php/7.0/mods-available/oci8.ini /etc/php/7.0/fpm/conf.d/20-oci8.ini

我不知道为什么,但是当我(重新)启动 php7.0-fpm 时收到此警告:

# service php7.0-fpm restart * Restarting PHP 7.0 FastCGI Process Manager php-fpm7.0 Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/oci8.so' - libmql1.so: cannot open shared object file: No such file or directory in Unknown on line 0

oci8.so 和 libmql1.so 的位置似乎没问题:

# ll /usr/lib/oracle/12.2/instantclient/
total 216700
drwxrwxrwx 3 root www-data      4096 Dec 11 15:12 ./
drwxr-xr-x 4 root www-data      4096 Dec 12 08:24 ../
-rwxrwxrwx 1 root www-data       363 Jan 26  2017 BASIC_README*
-rwxrwxrwx 1 root www-data     44220 Jan 26  2017 adrci*
-rwxrwxrwx 1 root www-data     57272 Jan 26  2017 genezi*
lrwxrwxrwx 1 root www-data        52 Dec 11 15:02 libclntsh.so -> /usr/lib/oracl
e/12.2/instantclient/libclntsh.so.12.1*
-rwxrwxrwx 1 root www-data  71638263 Jan 26  2017 libclntsh.so.12.1*
-rwxrwxrwx 1 root www-data   8033199 Jan 26  2017 libclntshcore.so.12.1*
-rwxrwxrwx 1 root www-data   2981501 Jan 26  2017 libipc1.so*
-rwxrwxrwx 1 root www-data    539065 Jan 26  2017 libmql1.so*
-rwxrwxrwx 1 root www-data   6568149 Jan 26  2017 libnnz12.so*
lrwxrwxrwx 1 root root            50 Dec 11 15:12 libocci.so -> /usr/lib/oracle/
12.2/instantclient/libocci.so.12.1*
-rwxrwxrwx 1 root www-data   2218687 Jan 26  2017 libocci.so.12.1*
-rwxrwxrwx 1 root www-data 124771800 Jan 26  2017 libociei.so*
-rwxrwxrwx 1 root www-data    158543 Jan 26  2017 libocijdbc12.so*
-rwxrwxrwx 1 root www-data    380996 Jan 26  2017 libons.so*
-rwxrwxrwx 1 root www-data    116563 Jan 26  2017 liboramysql12.so*
-rwxrwxrwx 1 root www-data   4036257 Jan 26  2017 ojdbc8.jar*
drwxrwxrwx 5 root www-data      4096 Jan 26  2017 sdk/
-rwxrwxrwx 1 root www-data    240476 Jan 26  2017 uidrvci*
-rwxrwxrwx 1 root www-data     74230 Jan 26  2017 xstreams.jar*

我已将这 4 行添加到 /etc/php/7.0/fpm/pool.d/www.conf 中:

env[LD_LIBRARY_PATH] = /usr/lib/oracle/12.2/instantclient env[TNS_ADMIN] = /etc/oracle env[ORACLE_BASE] = /usr/lib/oracle/12.2/instantclient env[ORACLE_HOME] = /usr/lib/oracle/12.2/instantclient

我会错过什么吗?

谢谢

尝试在 /etc/apache2/envvars 中添加那些环境变量 在文件末尾添加,例如

  • 导出LD_LIBRARY_PATH=/usr/lib/oracle/12.2/instantclient

  • 导出TNS_ADMIN=/etc/oracle

  • 导出ORACLE_BASE=/usr/lib/oracle/12.2/instantclient

  • 导出ORACLE_HOME=/usr/lib/oracle/12.2/instantclient

这样 apache 用户将在运行时使用这些变量。 还要检查 user/group 权限,它必须是 www-data:www-data

没关系! 我在 /etc/ld.so.conf.d/oracle-instantclient.conf

中遗漏了一个 .conf
RUN echo "instantclient,/usr/lib/oracle/12.2/instantclient"| pecl install oci8 && \
echo "extension=oci8.so" > /etc/php/7.0/mods-available/oci8.ini && \
ln -s /etc/php/7.0/mods-available/oci8.ini /etc/php/7.0/fpm/conf.d/20-oci8.ini && \
echo /usr/lib/oracle/12.2/instantclient > /etc/ld.so.conf.d/oracle-instantclient.conf && \
ldconfig