Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile PHP OCI8 extension under Alpinelinux

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!

like image 456
Sergey Kolodyazhnyy Avatar asked Dec 24 '22 04:12

Sergey Kolodyazhnyy


2 Answers

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/
like image 124
Serge Populov Avatar answered Jan 01 '23 01:01

Serge Populov


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
like image 22
kopiro Avatar answered Jan 01 '23 01:01

kopiro