4

I'm trying to compile 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.

Is there any existent compiled PHP OCI8 extension I can use? Or is there any workaround to make oci8 extension and oracle instant client work with alpinelinux.

Thanks in advance!

4 Answers4

5

My solution for Alpine turned out to be simple: use Instant Client v11 (11.2.0.4) instead of 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/
Serge Populov
  • 1,725
  • 16
  • 19
  • I used `docker-php-ext-configure` and `docker-php-ext-install` to build the extension rather than `pecl` - this saved installing and removing a lot of packages. `RUN docker-php-ext-configure oci8 --with-oci8=instantclient,$ORACLE_HOME && docker-php-ext-install oci8` – Rick Oct 02 '18 at 15:15
  • @Rick for some reason we use pure alpine as base image, rather than official PHP image, so ```docker-php-ext-configure``` doesn't work for me, otherwise - yes, it may be easier. – Serge Populov Oct 04 '18 at 07:59
4

Try these commands.

It works under Docker on Alpine.

But, you have to install the GLIB Alpine compatibility layer: 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
kopiro
  • 689
  • 4
  • 11
1

People who've tried Alpine haven't found a way. The problem is not specific to PHP, so check other languages that also use Oracle Instant Client and have tried Alpine. For example, see the Alpine issue https://github.com/sgerrand/alpine-pkg-glibc/issues/31

Christopher Jones
  • 9,449
  • 3
  • 24
  • 48
  • Yep, I was expecting it to be related with Oracle and their dependency on non-standard glibc calls. Apparently there is no way to get it working at the moment. Thanks for your comment anyway :) – Sergey Kolodyazhnyy Jul 22 '16 at 14:56
  • Let me know too if something new would happen with problem – SLY Jul 16 '17 at 11:48
1
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
Patrick
  • 9
  • 1