I am new to setting up Oracle Database on a server, and I am setting up NGINX PHP-FPM 7.4 Alpine and Oracle Database using Docker on a CentOS7 server (centos-release-7-7.1908.0.el7.centos.x86_64).
I have already successfully installed the Oracle Database in Docker, so my next objective is to be able to connect to the Oracle Database using the function oci_connect
in PHP. This is where I am stuck. I have been following this and downloading the required software such as the Oracle Instant Client. (I used the latest version as of this writing: instantclient-basic-linux.x64-19.6.0.0.0dbru )
I got the following files for docker-compose:
docker-compose.yml:
version: '3'
services:
web:
image: nginx:alpine
ports:
- 8080:80
volumes:
- ./web:/var/www/web
- ./log:/var/log/nginx
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
restart: always
phpfpm:
build:
context: ./php-fpm
dockerfile: Dockerfile
volumes:
- ./web:/var/www/web
php-fpm/Dockerfile:
FROM php:7.4-fpm-alpine
RUN mkdir -p /var/www/web
# custom.ini is basically my php.ini
ADD custom.ini /usr/local/etc/php/conf.d/custom.ini
RUN apk add --update --no-cache \
libzip-dev \
curl-dev \
libxml2-dev \
libpng-dev \
$PHPIZE_DEPS \
php7-openssl
RUN docker-php-ext-configure gd
RUN docker-php-ext-install \
curl \
dom \
gd \
json \
tokenizer \
zip
# Install Oracle Instantclient
RUN mkdir /opt/oracle \
&& cd /opt/oracle
ADD instantclient-basic-linux.x64-19.6.0.0.0dbru.zip /opt/oracle/instantclient-basic-linux.x64-19.6.0.0.0dbru.zip
ADD instantclient-sdk-linux.x64-19.6.0.0.0dbru.zip /opt/oracle/instantclient-sdk-linux.x64-19.6.0.0.0dbru.zip
RUN rm -rf /opt/oracle/instantclient_19_6/*
RUN unzip /opt/oracle/instantclient-basic-linux.x64-19.6.0.0.0dbru.zip -d /opt/oracle \
&& unzip /opt/oracle/instantclient-sdk-linux.x64-19.6.0.0.0dbru.zip -d /opt/oracle \
&& ln -sf /opt/oracle/instantclient_19_6/libclntsh.so.19.1 /opt/oracle/instantclient_19_6/libclntsh.so \
&& ln -sf /opt/oracle/instantclient_19_6/libclntshcore.so.19.1 /opt/oracle/instantclient_19_6/libclntshcore.so \
&& ln -sf /opt/oracle/instantclient_19_6/libocci.so.19.1 /opt/oracle/instantclient_19_6/libocci.so \
&& rm -rf /opt/oracle/*.zip
# Install Oracle extensions
RUN docker-php-ext-configure pdo_oci --with-pdo-oci=instantclient,/opt/oracle/instantclient_19_6,19.1 \
&& echo 'instantclient,/opt/oracle/instantclient_19_6/' | pecl install oci8 \
&& docker-php-ext-install \
pdo_oci \
&& docker-php-ext-enable \
oci8
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
EXPOSE 9000
CMD ["php-fpm"]
In addition, I have also added these Oracle related 'extension' into custom.ini (basically my php.ini) which is referred in php-fpm/Dockerfile above:
expose_php = Off
extension=oci8.so
extension=pdo_oci.so
docker-compose up
When I do docker-compose up, I see that the build process could be completed but I got into the following warnings in the build output:
...
...
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/
PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so.so: No such file or directory)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_oci.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so.so: No such file or directory)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so.so: No such file or directory)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_oci.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so.so: No such file or directory)) in Unknown on line 0
...
...
This "Unable to load dynamic library 'oci8.so' and 'pdo_oci.so'" occurs in the build roughly 20 times.
After the whole build process is completed, php-fpm runs but it also have similar warning messages above:
Successfully built c5fe0a0bc6ab
Successfully tagged nginx-php_phpfpm:latest
Starting nginx-php_web_1 ... done
Creating nginx-php_phpfpm_1 ... done
Attaching to nginx-php_web_1, nginx-php_phpfpm_1
phpfpm_1 | [20-Mar-2020 11:30:03] NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so (Error loading shared library libnsl.so.1: No such file or directory (needed by /opt/oracle/instantclient_19_6//libclntsh.so.19.1)), /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so.so: No such file or directory)) in Unknown on line 0
phpfpm_1 | [20-Mar-2020 11:30:03] NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_oci.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so (Error loading shared library libnsl.so.1: No such file or directory (needed by /opt/oracle/instantclient_19_6/libclntsh.so.19.1)), /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so.so: No such file or directory)) in Unknown on line 0
phpfpm_1 | [20-Mar-2020 11:30:03] NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so (Error loading shared library libnsl.so.1: No such file or directory (needed by /opt/oracle/instantclient_19_6//libclntsh.so.19.1)), /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so.so: No such file or directory)) in Unknown on line 0
phpfpm_1 | [20-Mar-2020 11:30:03] NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_oci.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so (Error loading shared library libnsl.so.1: No such file or directory (needed by /opt/oracle/instantclient_19_6/libclntsh.so.19.1)), /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20190902/pdo_oci.so.so: No such file or directory)) in Unknown on line 0
phpfpm_1 | [20-Mar-2020 11:30:03] NOTICE: fpm is running, pid 1
phpfpm_1 | [20-Mar-2020 11:30:03] NOTICE: ready to handle connections
PHP Test
I also tested this with a .php file:
<?php
$objConnect = oci_connect('SYSTEM', 'xxxxxxxxxx', 'x.x.x.x');
if($objConnect)
{
echo "Oracle Server Connected";
}
?>
Obviously, this yields on the browser:
Fatal error: Uncaught Error: Call to undefined function oci_connect() in /var/www/web/public/index.php:3 Stack trace: #0 {main} thrown in /var/www/web/public/index.php on line 3
Looking into the container
I also tried look into the container itself with : docker exec -it 623 sh
to check into the directory the app is referring to:
/usr/local/lib/php/extensions/no-debug-non-zts-20190902 # ls -la
total 2588
drwxr-xr-x 1 root root 39 Mar 20 11:29 .
drwxr-xr-x 1 root root 39 Mar 19 22:43 ..
-rwxr-xr-x 1 root root 122288 Mar 20 11:28 curl.so
-rwxr-xr-x 1 root root 249824 Mar 20 11:28 dom.so
-rwxr-xr-x 1 root root 433280 Mar 20 11:29 gd.so
-rwxr-xr-x 1 root root 54944 Mar 20 11:29 json.so
-rw-r--r-- 1 root root 911808 Mar 20 11:29 oci8.so
-rwxr-xr-x 1 root root 579504 Mar 19 22:43 opcache.so
-rwxr-xr-x 1 root root 51368 Mar 20 11:29 pdo_oci.so
-rwxr-xr-x 1 root root 108128 Mar 19 22:43 sodium.so
-rwxr-xr-x 1 root root 35952 Mar 20 11:29 tokenizer.so
-rwxr-xr-x 1 root root 89600 Mar 20 11:29 zip.so
I see that all the files are there, so what's with the Unable to load dynamic library 'oci8.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/oci8.so
then? How come it cannot find the library when it is there in the container?
Other things I have tried:
I have also tried looking around StackOverflow, and tried this answer but still, adding ENV LD_LIBRARY_PATH /usr/local/lib/php/extensions/no-debug-non-zts-20190902
into my Dockerfile does NOT solve the problem.
Am I missing something in this case? What must I do in order for it to be able to resolve for the libraries? Or are there some incompatibility issues in this case?