在Alpinelinux下编译PHP OCI8扩展
Compile PHP OCI8 extension under Alpinelinux
我正在尝试编译 PHP OCI8 extension and run it under Alpinelinux. But it seems extension has some dependencies on symbols defined in glibc
but missing in musl libc。
是否有现成的 PHP OCI8 扩展可供我使用?或者是否有任何解决方法可以使 oci8 扩展和 oracle 即时客户端与 alpinelinux 一起工作。
提前致谢!
用过Alpine的人都没有找到方法。该问题并非特定于 PHP,因此请检查也使用 Oracle Instant Client 并尝试过 Alpine 的其他语言。例如,参见 Alpine 问题 https://github.com/sgerrand/alpine-pkg-glibc/issues/31
试试这些命令。
它在 Alpine 上 Docker 下工作。
但是,您必须安装 GLIB Alpine 兼容层:https://github.com/sgerrand/alpine-pkg-glibc
# Install OCI8
COPY ./oracle-sdk /tmp/oracle-sdk
RUN apk add --no-cache libaio-dev && \
unzip /tmp/oracle-sdk/instantclient-basic-linux.x64-12.2.0.1.0.zip -d /usr/local/ && \
unzip /tmp/oracle-sdk/instantclient-sdk-linux.x64-12.2.0.1.0.zip -d /usr/local/ && \
unzip /tmp/oracle-sdk/instantclient-sqlplus-linux.x64-12.2.0.1.0.zip -d /usr/local/ && \
ln -s /usr/local/instantclient_12_2 /usr/local/instantclient && \
ln -s /usr/local/instantclient/libclntsh.so.* /usr/local/instantclient/libclntsh.so && \
ln -s /usr/local/libclntshcore.so.* /usr/local/instantclient/libclntshcore.so && \
ln -s /usr/local/instantclient/libocci.so.* /usr/local/instantclient/libocci.so && \
ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus && \
docker-php-ext-configure oci8 --with-oci8=instantclient,/usr/local/instantclient && \
docker-php-ext-install oci8 && \
rm -rf /tmp/oracle-sdk
我的 Alpine 解决方案原来很简单:使用 Instant Client v11 (11.2.0.4) 而不是 v12 (12.2.0.1):
ENV LD_LIBRARY_PATH /usr/local/instantclient
ENV ORACLE_HOME /usr/local/instantclient
# Install Oracle Client and build OCI8 (Oracle Command Interface 8 - PHP extension)
RUN apk add php7-pear php7-dev gcc musl-dev libnsl libaio &&\
## Download and unarchive Instant Client v11
curl -o /tmp/basic.zip https://raw.githubusercontent.com/bumpx/oracle-instantclient/master/instantclient-basic-linux.x64-11.2.0.4.0.zip && \
curl -o /tmp/sdk.zip https://raw.githubusercontent.com/bumpx/oracle-instantclient/master/instantclient-sdk-linux.x64-11.2.0.4.0.zip && \
curl -o /tmp/sqlplus.zip https://raw.githubusercontent.com/bumpx/oracle-instantclient/master/instantclient-sqlplus-linux.x64-11.2.0.4.0.zip && \
unzip -d /usr/local/ /tmp/basic.zip && \
unzip -d /usr/local/ /tmp/sdk.zip && \
unzip -d /usr/local/ /tmp/sqlplus.zip && \
## Links are required for older SDKs
ln -s /usr/local/instantclient_11_2 ${ORACLE_HOME} && \
ln -s ${ORACLE_HOME}/libclntsh.so.* ${ORACLE_HOME}/libclntsh.so && \
ln -s ${ORACLE_HOME}/libocci.so.* ${ORACLE_HOME}/libocci.so && \
ln -s ${ORACLE_HOME}/lib* /usr/lib && \
ln -s ${ORACLE_HOME}/sqlplus /usr/bin/sqlplus &&\
ln -s /usr/lib/libnsl.so.2.0.0 /usr/lib/libnsl.so.1 &&\
## Build OCI8 with PECL
echo "instantclient,${ORACLE_HOME}" | pecl install oci8 &&\
echo 'extension=oci8.so' > /etc/php7/conf.d/30-oci8.ini &&\
# Clean up
apk del php7-pear php7-dev gcc musl-dev &&\
rm -rf /tmp/*.zip /var/cache/apk/* /tmp/pear/
FROM php:alpine3.13
RUN apk add --no-cache composer libaio libc6-compat \
&& wget https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-basiclite-linux.x64-21.1.0.0.0.zip -O- | busybox unzip -q - \
&& wget https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-sdk-linux.x64-21.1.0.0.0.zip -O- | busybox unzip -q - \
&& cp /instantclient_21_1/libclntsh.so.21.1 /instantclient_21_1/libclntsh.so && cp /lib64/ld-linux-x86-64.so.2 /instantclient_21_1/ && cp /lib/libc.so.6 /usr/lib/libresolv.so.2 \
&& docker-php-ext-configure oci8 --with-oci8=instantclient,/instantclient_21_1 && docker-php-ext-install oci8
我正在尝试编译 PHP OCI8 extension and run it under Alpinelinux. But it seems extension has some dependencies on symbols defined in glibc
but missing in musl libc。
是否有现成的 PHP OCI8 扩展可供我使用?或者是否有任何解决方法可以使 oci8 扩展和 oracle 即时客户端与 alpinelinux 一起工作。
提前致谢!
用过Alpine的人都没有找到方法。该问题并非特定于 PHP,因此请检查也使用 Oracle Instant Client 并尝试过 Alpine 的其他语言。例如,参见 Alpine 问题 https://github.com/sgerrand/alpine-pkg-glibc/issues/31
试试这些命令。
它在 Alpine 上 Docker 下工作。
但是,您必须安装 GLIB Alpine 兼容层:https://github.com/sgerrand/alpine-pkg-glibc
# Install OCI8
COPY ./oracle-sdk /tmp/oracle-sdk
RUN apk add --no-cache libaio-dev && \
unzip /tmp/oracle-sdk/instantclient-basic-linux.x64-12.2.0.1.0.zip -d /usr/local/ && \
unzip /tmp/oracle-sdk/instantclient-sdk-linux.x64-12.2.0.1.0.zip -d /usr/local/ && \
unzip /tmp/oracle-sdk/instantclient-sqlplus-linux.x64-12.2.0.1.0.zip -d /usr/local/ && \
ln -s /usr/local/instantclient_12_2 /usr/local/instantclient && \
ln -s /usr/local/instantclient/libclntsh.so.* /usr/local/instantclient/libclntsh.so && \
ln -s /usr/local/libclntshcore.so.* /usr/local/instantclient/libclntshcore.so && \
ln -s /usr/local/instantclient/libocci.so.* /usr/local/instantclient/libocci.so && \
ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus && \
docker-php-ext-configure oci8 --with-oci8=instantclient,/usr/local/instantclient && \
docker-php-ext-install oci8 && \
rm -rf /tmp/oracle-sdk
我的 Alpine 解决方案原来很简单:使用 Instant Client v11 (11.2.0.4) 而不是 v12 (12.2.0.1):
ENV LD_LIBRARY_PATH /usr/local/instantclient
ENV ORACLE_HOME /usr/local/instantclient
# Install Oracle Client and build OCI8 (Oracle Command Interface 8 - PHP extension)
RUN apk add php7-pear php7-dev gcc musl-dev libnsl libaio &&\
## Download and unarchive Instant Client v11
curl -o /tmp/basic.zip https://raw.githubusercontent.com/bumpx/oracle-instantclient/master/instantclient-basic-linux.x64-11.2.0.4.0.zip && \
curl -o /tmp/sdk.zip https://raw.githubusercontent.com/bumpx/oracle-instantclient/master/instantclient-sdk-linux.x64-11.2.0.4.0.zip && \
curl -o /tmp/sqlplus.zip https://raw.githubusercontent.com/bumpx/oracle-instantclient/master/instantclient-sqlplus-linux.x64-11.2.0.4.0.zip && \
unzip -d /usr/local/ /tmp/basic.zip && \
unzip -d /usr/local/ /tmp/sdk.zip && \
unzip -d /usr/local/ /tmp/sqlplus.zip && \
## Links are required for older SDKs
ln -s /usr/local/instantclient_11_2 ${ORACLE_HOME} && \
ln -s ${ORACLE_HOME}/libclntsh.so.* ${ORACLE_HOME}/libclntsh.so && \
ln -s ${ORACLE_HOME}/libocci.so.* ${ORACLE_HOME}/libocci.so && \
ln -s ${ORACLE_HOME}/lib* /usr/lib && \
ln -s ${ORACLE_HOME}/sqlplus /usr/bin/sqlplus &&\
ln -s /usr/lib/libnsl.so.2.0.0 /usr/lib/libnsl.so.1 &&\
## Build OCI8 with PECL
echo "instantclient,${ORACLE_HOME}" | pecl install oci8 &&\
echo 'extension=oci8.so' > /etc/php7/conf.d/30-oci8.ini &&\
# Clean up
apk del php7-pear php7-dev gcc musl-dev &&\
rm -rf /tmp/*.zip /var/cache/apk/* /tmp/pear/
FROM php:alpine3.13
RUN apk add --no-cache composer libaio libc6-compat \
&& wget https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-basiclite-linux.x64-21.1.0.0.0.zip -O- | busybox unzip -q - \
&& wget https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-sdk-linux.x64-21.1.0.0.0.zip -O- | busybox unzip -q - \
&& cp /instantclient_21_1/libclntsh.so.21.1 /instantclient_21_1/libclntsh.so && cp /lib64/ld-linux-x86-64.so.2 /instantclient_21_1/ && cp /lib/libc.so.6 /usr/lib/libresolv.so.2 \
&& docker-php-ext-configure oci8 --with-oci8=instantclient,/instantclient_21_1 && docker-php-ext-install oci8