phporacle-databaseoci8alpine-linux

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!


Solution

  • 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/