PHP Docker install pecl V8JS (Debian Buster) - php

I tried to install V8JS with this Dockerfile
FROM php:7.3-cli-buster
RUN apt-get update -y --fix-missing && apt-get upgrade -y;
# Install v8js
RUN apt-get install -y libv8-dev
RUN pecl install v8js
RUN docker-php-ext-enable v8js
but I got a configuration error:
checking for V8 files in default path... not found
configure: error: Please reinstall the v8 distribution ERROR:
`/tmp/pear/temp/v8js/configure
--with-php-config=/usr/local/bin/php-config --with-v8js' failed The command '/bin/sh -c pecl install v8js' returned a non-zero code: 1
full cli output:
Sending build context to Docker daemon 35.6MB
Step 1/5 : FROM php:7.3-cli-buster
---> c7ff0bf4f6fb
Step 2/5 : RUN apt-get update -y --fix-missing && apt-get upgrade -y;
---> Using cache
---> e151d6e061d2
Step 3/5 : RUN apt-get install -y libv8-dev
---> Using cache
---> fe35f48dd8cf
Step 4/5 : RUN pecl install v8js
---> Running in d9f4ba184d81
downloading v8js-2.1.1.tgz ...
Starting to download v8js-2.1.1.tgz (101,888 bytes)
.......................done: 101,888 bytes
28 source files, building
running: phpize
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
Please provide the installation prefix of libv8 [autodetect] : building in /tmp/pear/temp/pear-build-defaultuserEVh9Nq/v8js-2.1.1
running: /tmp/pear/temp/v8js/configure --with-php-config=/usr/local/bin/php-config --with-v8js
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20180731
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 1.1.1 (ok)
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for V8 Javascript Engine... yes, shared
checking for V8 files in default path... not found
configure: error: Please reinstall the v8 distribution
ERROR: `/tmp/pear/temp/v8js/configure --with-php-config=/usr/local/bin/php-config --with-v8js' failed
The command '/bin/sh -c pecl install v8js' returned a non-zero code: 1
How to resolve configuration error (due to lack of a path to the V8 files I guess) and install V8JS on PHP Docker FROM Debian Buster?
EDIT
Dockerfile from #saulotoledo answer works :)
Building image takes approx 60-90 min and the image size is 5.47GB vs base image (FROM) 7.3-cli-buster 367MB
to build Dockerfile php with V8JS copy the code from #saulotoledo answer and paste it into the file named Dockerfile
Then run in the same directory this command:
docker build --tag "test-php-js" .
Then run container this way:
docker run -it --rm --entrypoint="" --name="php-v8js" test-php-js /bin/sh
you should be logged into terminal of php-cli, type:
php -m
and you should see a list of enabled extensions including v8js
type:
php --ri v8js
to see some details, something like:
V8 Javascript Engine => enabled
V8 Engine Compiled Version => 7.4.288.21
V8 Engine Linked Version => 7.4.288.21
Version => 2.1.1
and now the cherry part you all have been waiting for - type:
php -r "(new V8Js())->executeString(\"print('Hello' + ' from JS ' + 'World!')\", 'basic.js');";
to see php running js code with V8JS support :D
Hello from JS World!
Note that I needed to put extra backslash \ in front of every JS doublequote " for the php -r command. But that's only due to running JS from php in cli mode as oneliner.
Normally you don't need that
See an official PHP documentation example
Does anyone know if it is possible to install and enable V8JS extension without building it from its source but by using Debian Buster package and PECL as I tried at the beginning?

Edit:
That should solve your issue (note that I am compiling it manually):
FROM php:7.3-cli-buster
ENV V8_VERSION=7.4.288.21
RUN apt-get update -y --fix-missing && apt-get upgrade -y;
# Install v8js (see https://github.com/phpv8/v8js/blob/php7/README.Linux.md)
RUN apt-get install -y --no-install-recommends \
libtinfo5 libtinfo-dev \
build-essential \
curl \
git \
libglib2.0-dev \
libxml2 \
python \
patchelf \
&& cd /tmp \
\
&& git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --progress --verbose \
&& export PATH="$PATH:/tmp/depot_tools" \
\
&& fetch v8 \
&& cd v8 \
&& git checkout $V8_VERSION \
&& gclient sync \
\
&& tools/dev/v8gen.py -vv x64.release -- is_component_build=true use_custom_libcxx=false
RUN export PATH="$PATH:/tmp/depot_tools" \
&& cd /tmp/v8 \
&& ninja -C out.gn/x64.release/ \
&& mkdir -p /opt/v8/lib && mkdir -p /opt/v8/include \
&& cp out.gn/x64.release/lib*.so out.gn/x64.release/*_blob.bin out.gn/x64.release/icudtl.dat /opt/v8/lib/ \
&& cp -R include/* /opt/v8/include/ \
&& apt-get install patchelf \
&& for A in /opt/v8/lib/*.so; do patchelf --set-rpath '$ORIGIN' $A;done
# Install php-v8js
RUN cd /tmp \
&& git clone https://github.com/phpv8/v8js.git \
&& cd v8js \
&& phpize \
&& ./configure --with-v8js=/opt/v8 LDFLAGS="-lstdc++" \
&& make \
&& make test \
&& make install
RUN docker-php-ext-enable v8js
Old answer:
I believe you need to compile the V8 manually. I am not sure yet why the libv8-dev is not enough. Since that does not work, you need to compile it because it is a requirement.
That said, this link may be helpful. But the official compilation instructions are presented here. After a few tests I noticed you need to add libtinfo5 (and maybe libtinfo-dev, to be safe, but you may try it without it) to your apt-get install, otherwise the ninja build in the instructions will fail.
After using that compilation instructions in your Dockerfile, the V8 will compile properly. After that you will still have some trouble with the pecl installation. Unfortunately I had to stop investigating the problem for now, the compilation takes some time. However, the following links may help you to solve your problem:
This one if you still have trouble compiling with ninja
This one presents another Dockerfile for compiling V8, but the base image is different and needs some adaptation.
I hope it helps. If you manage to have a working Dockerfile please share with us later. If I have some time later to investigate it and I have some progress I will edit my answer.

Thanks to saulotoledo I created example image that takes 950MB vs 398MB base image (php:7.3-cli-buster)
It works also with PHP FPM, just change
FROM php:7.3-cli-buster to FROM php:7.3-fpm-buster if you want FPM version.
Dockerfile
FROM php:7.3-cli-buster
ENV V8_VERSION=7.4.288.21
# php:7.3-cli-buster 398MB
RUN apt-get update -y --fix-missing && apt-get upgrade -y;
# Install required CLI tools
RUN apt-get install -y --no-install-recommends \
libtinfo5 libtinfo-dev \
build-essential \
curl \
git \
libglib2.0-dev \
libxml2 \
python \
patchelf
# Install V8, PHP's V8Js
RUN cd /tmp \
\
&& git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --progress --verbose \
&& export PATH="$PATH:/tmp/depot_tools" \
\
&& fetch v8 \
&& cd v8 \
&& git checkout $V8_VERSION \
&& gclient sync \
&& tools/dev/v8gen.py -vv x64.release -- is_component_build=true use_custom_libcxx=false \
\
&& cd /tmp/v8 \
&& ninja -C out.gn/x64.release/ \
&& mkdir -p /opt/v8/lib && mkdir -p /opt/v8/include \
&& cp out.gn/x64.release/lib*.so out.gn/x64.release/*_blob.bin out.gn/x64.release/icudtl.dat /opt/v8/lib/ \
&& cp -R include/* /opt/v8/include/ \
&& for A in /opt/v8/lib/*.so; do patchelf --set-rpath '$ORIGIN' $A;done \
\
&& cd /tmp \
&& git clone https://github.com/phpv8/v8js.git \
&& cd v8js \
&& phpize \
&& ./configure --with-v8js=/opt/v8 LDFLAGS="-lstdc++" \
&& make \
&& make test \
&& make install \
\
&& docker-php-ext-enable v8js \
\
&& rm -rf "/tmp/v8" \
&& rm -rf "/tmp/depot_tools"
# Image size after removing source files 950MB

This works without compiling v8 - it is very fast. Using distro packaged nodejs library. You can use current official php docker image
RUN apt-get install -y libnode-dev \
&& cp -s /usr/lib/x86_64-linux-gnu/libv8* /usr/local/lib/ \
&& cp -rs /usr/include/node/* /usr/local/include/ \
&& pecl install v8js \
&& echo "extension=v8js.so" > /usr/local/etc/php/conf.d/v8js.so

Related

How to install ZeroMQ for PHP on an Alpine Linux container?

To be able to push notifications via WebSockets from PHP using Ratchet, I need to install ZeroMQ as stated in the documentation. However I didn't find any information about how to do it for Alpine Linux. Most of the time what we can find is with apt-get, for example here. Same about the Docker images (Dockerfile) available on Docker hub.
Since the dependencies and their name seem different, how to do it with Alpine?
For those who face the same situation, I finally found how to do it:
FROM php:7-cli-alpine
RUN apk add autoconf gcc libzmq zeromq-dev zeromq coreutils build-base
RUN pecl install zmq-beta \
&& docker-php-ext-enable zmq
Source: https://smartango.com/2018/10/php-zmq-in-docker-and-checking-whether-the-c-compiler-works-no/
In php:8.0-fpm-alpine, pecl install zmq-beta threw an error and failed to compile, so I used this command:
FROM php:8.0-fpm-alpine
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN set -eux && \
apk add --update-cache --no-cache libzmq zeromq-dev zeromq && \
apk add --update-cache --no-cache --virtual=.build-php-dependencies \
autoconf gcc coreutils build-base git && \
git clone https://github.com/mkoppanen/php-zmq.git && \
cd php-zmq && \
phpize && \
./configure && \
make && \
make install && \
docker-php-ext-enable zmq && \
apk del .build-php-dependencies
Reference:
https://github.com/zeromq/php-zmq/issues/200#issuecomment-610161524

How to include MSSQL drivers for PHP in Google App Engine

I am building an app (PHP/Laravel) that is supposed to be deployed on Google's App Engine. One of the components of the app is to be able to connect to an MSSQL server. Everything worked fine when I was debugging it, but as soon as I deployed it to the App Engine - guess what? It does not work (error: could not find driver).
I went through the Google documentation and I found out that the MSSQL drivers (pdo_sqlsrv, sqlsrv) are not enabled nor available in the standard environment. I checked the flexible environment, but that's the same. The difference is that I can use my own runtime using Dockerfile.
I changed two lines of my app.yaml in the root directory:
runtime: custom
env: flex
Then I created my Dockerfile also in the root directory that was supposed to install sqlsrv and pdo_sqlsrv using PECL and enable it:
FROM gcr.io/google-appengine/php72:latest
ARG COMPOSER_FLAGS='--prefer-dist --ignore-platform-reqs --optimize-autoloader'
ENV COMPOSER_FLAGS=${COMPOSER_FLAGS}
ENV SWOOLE_VERSION=4.3.4
ENV DOCUMENT_ROOT=/app/public
ENV ACCEPT_EULA=Y
COPY . $APP_DIR
RUN apt-get update -y \
&& curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -\
&& curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update -y \
&& apt-get install -y \
unzip \
autoconf \
build-essential \
libmcrypt-dev \
libmpdec-dev \
libpq-dev \
unixodbc-dev \
msodbcsql17 \
mssql-tools \
php-common \
&& apt-get update \
&& pecl install \
decimal \
sqlsrv \
pdo_sqlsrv \
xdebug \
&& apt-get update \
&& phpenmod sqlsrv pdo_sqlsrv \
&& curl -o /tmp/swoole.tar.gz https://github.com/swoole/swoole-src/archive/v$SWOOLE_VERSION.tar.gz -L \
&& tar zxvf /tmp/swoole.tar.gz \
&& cd swoole-src* \
&& phpize \
&& ./configure \
--enable-coroutine \
--enable-async-redis \
--enable-coroutine-postgresql \
--enable-sqlsrv=static --with-pdo_sqlsrv=static \
&& make \
&& make install \
&& chown -R www-data.www-data $APP_DIR \
&& /build-scripts/composer.sh;
ENTRYPOINT ["/build-scripts/entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
EXPOSE 8080
I also have my own php.ini with two lines in the root directory:
extension = pdo_sqlsrv.so
extension = sqlsrv.so
According to the Google documentation, having this file in the root of an app will extend/replace their default php.ini with my configuration. However, I only found this statement in the docs for non-custom runtimes. I tested it out by changing the value of display_errors and then phpinfo(). The display_errors was still set to the default value and get_loaded_extensions() didn't display sqlsrv nor pdo_sqlsrv.
I checked the build-log and it seems that the drivers were properly installed, because in the 3714 lines I found:
Installing '/opt/php72/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20170718/sqlsrv.so'
install ok: channel://pecl.php.net/sqlsrv-5.8.1
.....
Installing '/opt/php72/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20170718/pdo_sqlsrv.so'
install ok: channel://pecl.php.net/pdo_sqlsrv-5.8.1
.....
configuration option "php_ini" is not set to php.ini location
You should add "extension=sqlsrv.so" to php.ini
configuration option "php_ini" is not set to php.ini location
You should add "extension=pdo_sqlsrv.so" to php.ini
Does anybody have any experience with this, please? What do I need to change in the Dockerfile to make Google App Engine enable the PHP extensions?
TL;DR: Add COPY php.ini /opt/php/lib/conf.d/ to Dockerfile.
Google documentation for GAE Standard environment says that you can place php.ini into the root directory, but I didn't find anything like that about Flexible env. Indeed, if you check Configuration File in phpinfo, and related. fields, they show other paths they're looking for php.ini, so you need to place the file there.
When I try that, the custom php.ini is loaded and allows overwriting display_errors, which you mentioned didn't work for you.
Multi-stage build
To avoid shipping C compiler and other build tools to production, which is wasteful and may slow down deployment of your app, you should also use docker's multi-stage build. Basically, you'll build the extensions in one "builder" container and copy the compiled result to the production container.
You Dockerfile will look sth like this:
FROM gcr.io/google-appengine/php72:latest AS builder
RUN apt-get update -y \
&& apt-get install -y \
unzip \
autoconf \
build-essential \
libmcrypt-dev \
libmpdec-dev \
libpq-dev \
unixodbc-dev \
php-common \
&& pecl install \
sqlsrv \
pdo_sqlsrv
FROM gcr.io/google-appengine/php72:latest
# Copy extensions from builder above
ENV PHP_EXT_DIR=/opt/php/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20170718/
COPY --from=builder $PHP_EXT_DIR/sqlsrv.so $PHP_EXT_DIR/
COPY --from=builder $PHP_EXT_DIR/pdo_sqlsrv.so $PHP_EXT_DIR/
# Install runtime dependencies
ENV ACCEPT_EULA=Y
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -\
&& curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update -y \
&& apt-get install -y \
msodbcsql17 \
mssql-tools
...

Oracle on Alpine linux

I am trying to install OCI8 extension on my Alpine Linux Docker environment. Although there are several places saying it won't work, there are some which say it actually does. I have a 3.4 version and for corporate reasons it is staying like that for now.
I have done this within my Docker conf:
# Install Oracle Client and build OCI8 (Oracel Command Interface 8 - PHP extension)
USER root
ENV LD_LIBRARY_PATH=/usr/local/instantclient
ENV ORACLE_HOME=/usr/local/instantclient
RUN apk update && apk upgrade
RUN apk add musl-dev libaio autoconf && apk add --update make
## Unzip Instant Client v12
RUN pecl channel-update pecl.php.net
COPY instantclient_12_2.zip /var/www/html/instantclient_12_2.zip
RUN unzip -d /usr/local/ /var/www/html/instantclient_12_2.zip
RUN ln -s /usr/local/instantclient_12_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
RUN apk add gcc; exit 0 # This has a history of failing sometimes
RUN echo "instantclient,/usr/local/instantclient" | pecl install oci8 &&\
echo 'extension=oci8.so' > /usr/local/etc/php/conf.d/30-oci8.ini &&\
rm -rf /tmp/*.zip /var/cache/apk/* /tmp/pear/
Now the build passes, and it looks okay, however when I do a php -v I am getting the following:
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/extensions/no-debug-non-zts-20160303/oci8.so' -
Error loading shared library libnsl.so.1: No such file or directory
(needed by /usr/local/instantclient/libclntsh.so.12.1) in Unknown on
line 0
PHP version is 7.1.12.
What I've tried is doing apk add libnsl but this returns me this error:
ERROR: unsatisfiable constraints: so:libtirpc.so.3 (missing):
So I tried also adding apk add libtirpc-dev (the 'plain' libtirpc isn't available for my version or something), but that changed nothing.
Any clues?
I share my version of docker that I made to work with the latest version of alpine and instantclient basiclite. The size of the docker image is 124 mb.
I share my github where you can download it
Docker + alpine + Instantclient Basiclite
Or you can see below the content of the dockerfile
FROM alpine:latest
# Install Instantclient Basic Light Oracle and Dependencies
RUN apk --no-cache add libaio libnsl libc6-compat curl && \
cd /tmp && \
curl -o instantclient-basiclite.zip https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip -SL && \
unzip instantclient-basiclite.zip && \
mv instantclient*/ /usr/lib/instantclient && \
rm instantclient-basiclite.zip && \
ln -s /usr/lib/instantclient/libclntsh.so.19.1 /usr/lib/libclntsh.so && \
ln -s /usr/lib/instantclient/libocci.so.19.1 /usr/lib/libocci.so && \
ln -s /usr/lib/instantclient/libociicus.so /usr/lib/libociicus.so && \
ln -s /usr/lib/instantclient/libnnz19.so /usr/lib/libnnz19.so && \
ln -s /usr/lib/libnsl.so.2 /usr/lib/libnsl.so.1 && \
ln -s /lib/libc.so.6 /usr/lib/libresolv.so.2 && \
ln -s /lib64/ld-linux-x86-64.so.2 /usr/lib/ld-linux-x86-64.so.2
ENV ORACLE_BASE /usr/lib/instantclient
ENV LD_LIBRARY_PATH /usr/lib/instantclient
ENV TNS_ADMIN /usr/lib/instantclient
ENV ORACLE_HOME /usr/lib/instantclient
I might be late to answer this. I got the same problem of having a alpine base image and add oracle client to that. So i came up with this solution -
https://github.com/Shrinidhikulkarni7/OracleClient_Alpine
Here is the Dockerfile, but you would also need the shell script in it for it to work.
FROM alpine:latest
ENV LD_LIBRARY_PATH=/lib
RUN wget https://download.oracle.com/otn_software/linux/instantclient/193000/instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
unzip instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
cp -r instantclient_19_3/* /lib && \
rm -rf instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
apk add libaio
ADD script.sh /root/script.sh
RUN /root/script.sh
Over here I'm directly downloading the oracle client inside image, setting the path, adding packages and finally using the shell script for creating symbolic link.
I'd recommend using an operating system supported by Oracle, thus avoiding the headache of hacking Alpine and the uncertainty that it won't fall over at a critical time. And thus giving you some confidence your business won't be negatively impacted. Try https://github.com/oracle/docker-images/tree/master/OracleInstantClient
Other comments
Don't set ORACLE_HOME when using Instant Client. That variable is
for full software installs.
Use ldconfig to set the system library path, see
the Instant Client installation instructions e.g. here.
Use Instant Client 19, which can connect to the same DB versions that 12.2 can. (19 is really the renamed terminal 12.2 release in the new versioning system)
Using Oracle Linux Docker images has the advantage that it will download and install the 19 Instant Client without you having to manually do the download.
See this blog for info about the 'slim' Oracle Linux container it uses.
Here is the Dockerfile For Golang With ORACLE-CLIENT
FROM golang:alpine
RUN apk update
ENV CLIENT_FILENAME instantclient-basic-linux.x64-12.1.0.1.0.zip
WORKDIR /opt/oracle/lib
ADD https://github.com/bumpx/oracle-instantclient/raw/master/${CLIENT_FILENAME} .
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
apk add --update libaio libnsl && \
ln -s /usr/lib/libnsl.so.2 /usr/lib/libnsl.so.1
RUN LIBS="*/libociei.so */libons.so */libnnz12.so */libclntshcore.so.12.1 */libclntsh.so.12.1" && \
unzip ${CLIENT_FILENAME} ${LIBS} && \
for lib in ${LIBS}; do mv ${lib} /usr/lib; done && \
ln -s /usr/lib/libclntsh.so.12.1 /usr/lib/libclntsh.so && \
rm ${CLIENT_FILENAME}
RUN mkdir /app
ADD . /app
WORKDIR /app
RUN apk add git
RUN apk add libc-dev
RUN apk add gcc
RUN go mod tidy
RUN go build -o main .
CMD ["/app/main"]
I was just tackling a similar problem to this using the Godror Golang Driver for Oracle. I was never able to solve this on using an Alpine image. The problem eventually came that libint.sh, would never fully install to be recognized by the system. Even changing the docker file to using the Glibc library.
How i eventually fixed the issue was to use the images from Oracle itself. The full version not the slim images that can be seen here: https://github.com/oracle/docker-images/tree/master/OracleLinuxDevelopers
you then have to install golang and then your Instant client and Oracle dependencies if you need it.
FROM oraclelinux:7 as builder
RUN yum install -y oracle-golang-release-el7 && \
yum install -y git && \
yum install -y golang unzip
COPY . /app
RUN go version
WORKDIR /app
{Your Docker Specific Commands Here}
{Insert Build Specific Environment Variables here}
#Oracle Specific Environment Variables
{Insert Oracle Env Variables here}
WORKDIR /root/
#Install oracle dependencies
RUN yum install -y wget unzip libaio && \
rm -rf /var/cache/yum
#install Oracle Instant Client
RUN wget https://download.oracle.com/otn_software/linux/instantclient/199000/instantclient-basic-linux.x64-19.9.0.0.0dbru.zip -O /tmp/instantclient.zip && \
unzip /tmp/instantclient.zip -d /usr/lib/instantclient && \
rm /tmp/instantclient.zip
#Install Oracle SDK
RUN wget https://download.oracle.com/otn_software/linux/instantclient/199000/instantclient-sdk-linux.x64-19.9.0.0.0dbru.zip -O /tmp/instantclient-sdk-linux.x64-19.9.0.0.0.zip && \
unzip /tmp/instantclient-sdk-linux.x64-19.9.0.0.0.zip -d /usr/lib/ && \
rm /tmp/instantclient-sdk-linux.x64-19.9.0.0.0.zip
#Install Oracle Tools through SQLPlus
RUN wget https://download.oracle.com/otn_software/linux/instantclient/199000/instantclient-sqlplus-linux.x64-19.9.0.0.0dbru.zip -O /tmp/instantclient-sqlplus-linux.x64-19.9.0.0.0.zip && \
unzip /tmp/instantclient-sqlplus-linux.x64-19.9.0.0.0.zip -d /usr/lib/ && \
rm /tmp/instantclient-sqlplus-linux.x64-19.9.0.0.0.zip
WORKDIR /app
COPY --from=builder /app/cmd/svr .
EXPOSE 8000
CMD ["./app"]
Again this is how i solved the problem for a Golang API. There may be others that solved the Alpine issue but i was never able to get it to work, even using older version of the Oracle Instant Client.
Try this Docker file. Start from the basic alpine linux image and add the required packages.
FROM alpine:3.13
WORKDIR /project
RUN wget https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-basiclite-linux.x64-21.1.0.0.0.zip -qO- | busybox unzip -q - && \
wget https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-sqlplus-linux.x64-21.1.0.0.0.zip -qO- | busybox unzip -q - && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-2.33-r0.apk -q
RUN apk add --allow-untrusted libaio glibc-2.33-r0.apk
RUN cd instantclient_21_1 && cp /usr/lib/libaio.so.1 /lib/libc.musl-x86_64.so.1 . && chmod +x sqlplus
ENV LD_LIBRARY_PATH=/project/instantclient_21_1

How to install PHP soap extension on Alpine 3.6

I'm having issues trying to install and enable the PHP soap extension. I'm running the base image php:7.2-fpm-alpine3.6 inside a Docker container that has instructions like below in the Dockerfile. It's unclear to me how extensions are installed on Alpine. It seems to use docker-php-ext-install from what I can infer.
Dockerfile (I adopted this from somewhere):
RUN apk --no-cache add \
freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev \
wget \
git \
nginx \
ca-certificates \
supervisor \
bash \
nano \
&& docker-php-ext-install \
mysqli \
pdo_mysql \
opcache \
...
So, I tried
docker-php-ext-install soap
which told me configure: error: xml2-config not found. Please check your libxml2 installation. I tried a bunch of stuff, but
apk add --no-cache libxml2-dev
seemed to do something. I followed this again with docker-php-ext-install soap, which outputted
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp.la modules/* libs/*
At this point, I did not run make test, as it's unclear where I'm suppose to go find this Makefile. I searched under /usr/local/lib/php/extensions/no-debug-non-zts-20170718/, and soap.so was already there. Furthermore, my commands already enabled it for PHP-FPM. php -i showed /usr/local/etc/php/conf.d/docker-php-ext-soap.ini,.
I'm not entirely sure what I did. Is this (docker-php-ext-install) how you install extensions on this OS?
The PHP SOAP extension requires the PHP XML extension, as documented here: http://php.net/manual/en/soap.requirements.php
I expect you need to install that first.
Presumably docker-php-ext-install xml.
You shouldn't need to compile the XML library yourself as it will be part of the extension.
The solution is:
RUN set -ex && apk --no-cache add libxml2-dev
RUN docker-php-ext-install soap
You can add a utility to your image using this package
Example:
FROM php:7.2-cli
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions gd xdebug
If you want, you can remove the last line and enter the container to play around with adding packages.
docker exec -it <container_id> bash # (swap bash for sh if using alpine)
Then you can just type install-php-extensions <ext>
Not every alpine distribution contains docker-php-ext commands etc, and I don't know how to add them easily, it did not look simple at all to me.
Anyway, any php extension can be easily installed by issuing this alpine install command
to find any php extension
apk search -v 'php' |grep ldap
result
phpldapadmin-1.2.3-r4 - Web front-end for managing OpenLDAP
php7-ldap-7.2.22-r0 - PHP7 extension: LDAP
php5-ldap-5.6.40-r0 - ldap extension for PHP
to further install the extension, one must supply its name in a form without the suffix version part , eg. without -7.2.22-r0 in php7-ldap-7.2.22-r0 so it's php7-ldap
like this
apk install php7-ldap

php 5.3 compilation failed using postgresq93-devel into Docker image

I am using a custom compilation based on PHP 5.3 and I need to upgrade the postgresql version from 9.2 to 9.3.
I am using docker for my infrastructure and the new lines I added was
yum remove postgresql -y && \
rpm -i /tmp/postgresql93.rpm && \
yum install postgresql93 postgresql93-devel -y && \
rm -rf /tmp/postgresql93.rpm && \
The compilation failed and the message was:
checking for pg_config... not found
configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
Then I added the postgresql-devel package into the upgrade lines
yum remove postgresql -y && \
rpm -i /tmp/postgresql93.rpm && \
yum install postgresql-devel postgresql93 postgresql93-devel -y && \
rm -rf /tmp/postgresql93.rpm && \
I wonder why using the postgresql-devel is working if I also installed the postgresql93-devel.
In my previous compilation I was using postgresql-devel but I removed and I thought the postgresql93-devel should be work but it didn't.
Any idea why is this happening? What is the difference here and why do I need to use postgresql-devel either way?

Categories