title: Not able to connect PHP application to db2 database on remote server
body: <p>Been struggling connecting a PHP site to a remote DB2 database for the last three days in <a href="https://github.com/bohsen/nginx-db2" rel="nofollow noreferrer">a docker-compose project I'm working on</a>. I keep getting <code>Connection failed</code>:</p>
  <pre><code>Error: 58031
  [IBM][CLI Driver] SQL1031N The database directory cannot be found on the indicated file system. SQLSTATE=58031 SQLCODE=-1031
  </code></pre>
  <p>Here's my docker-compose setup:</p>
  <pre><code># /docker-compose.yml
  ---
  version: '3.8'
  services:
    web:
      container_name: nginx
      depends_on:
        - db2
      image: nginx:latest
      ports:
        - &quot;80:80&quot;
      volumes:
        - ./nginx.conf:/etc/nginx/conf.d/nginx.conf
        - ./app:/app
      links:
        - php
        - db2
    php:
      container_name: php
      build:
        context: .
        dockerfile: PHP.Dockerfile
      volumes:
        - ./app:/app
      links:
        - db2
    db2:
      container_name: db2.rn.dk
      image: ibmcom/db2:latest
      hostname: db2.rn.dk
      privileged: true
      ports:
        - &quot;50000:50000&quot;
      environment:
        - DB_NAME=testdb
        - DB_USER=db2inst1
        - DB_PASSWORD=ChangeMe!
        - LICENSE=accept
        ## Creates the database DB_NAME, if its not exists
        - STARTUP_MODE=createIfNotExists
        - DB_CREATE_SCRIPT=create_wdemo.sql
        ## loads an old backup of DB_NAME, 
        ## if the dabase DB_NAME does not exist
        # - STARTUP_MODE=restoreIfNotExists
        # - DB_BACKUP=wdemo.tar.gz
      volumes:
        - './data/db2:/database'
  </code></pre>
  <p>And the PHP.dockerfile:</p>
  <pre><code>FROM php:fpm
  
  RUN apt-get update -qq &gt; /dev/null &amp;&amp; \
      apt-get install unzip
  RUN pecl install xdebug &amp;&amp; docker-php-ext-enable xdebug
  
  # Documentation
  # https://www.ibm.com/docs/en/db2/11.5?topic=dsd-installing-data-server-driver-odbc-cli-software-linux-unix-operating-systems
  # https://www.ibm.com/docs/en/db2/11.5?topic=environment-configuring
  # https://stackoverflow.com/questions/37066985/php-connection-to-db2
  # https://github.com/nagstaku/php_db2
  # https://github.com/php/pecl-database-ibm_db2
  # https://github.com/php/pecl-database-pdo_ibm
  
  # Install DB2 php-extensions
  
  RUN mkdir -p /opt/ibm/ &amp;&amp; curl https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/linuxx64_odbc_cli.tar.gz | tar -xz -C /opt/ibm/
  # if you prefer to keep the file locally, download it and use:
  
  ## set env vars needed for PECL install
  ENV IBM_DB_HOME=/opt/ibm/clidriver
  ENV LD_LIBRARY_PATH=/opt/ibm/clidriver/lib
  # ENV IBM_DB_HOME=/opt/ibm/dsdriver
  # ENV LD_LIBRARY_PATH=IBM_DB_HOME/lib
  
  ## install ibm_db2 drivers
  RUN pecl install ibm_db2 pdo_ibm
  RUN echo &quot;extension=ibm_db2.so&quot; &gt; /usr/local/etc/php/conf.d/ibm_db2.ini
  RUN echo &quot;extension=ibm_db2.so&quot; &gt;&gt; /usr/local/etc/php/php.ini
  RUN echo &quot;extension=pdo.so&quot; &gt;&gt; /usr/local/etc/php/php.ini
  RUN echo &quot;extension=pdo_ibm.so&quot; &gt;&gt; /usr/local/etc/php/php.ini
  
  # 
  # RUN echo &quot;ibm_db2.instance_name=db2inst1&quot; &gt;&gt; /usr/local/etc/php/php.ini
  </code></pre>
  <p>index.php</p>
  <pre><code>&lt;?php
  ...
  $database = 'testdb';
  $user = 'db2inst1';
  $password = 'ChangeMe!';
  $hostname = 'db2.rn.dk';
  $port = 50000;
  
  $conn_string =
      &quot;DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;&quot; .
      &quot;HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;&quot;;
  $conn = db2_connect($conn_string, '', '');
  if ($conn) {
      echo &quot;Connection succeeded.\n&quot;;
      db2_close($conn);
  } else {
      echo &quot;&lt;p&gt;&lt;b&gt;Using ibm_db2 extension:&lt;/b&gt;&lt;/p&gt;&quot;;
      echo &quot;&lt;p&gt;&lt;u&gt;Connection failed:&lt;/u&gt;&lt;/p&gt;&quot;;
      echo &quot;&lt;p&gt;Error: &quot;.db2_conn_error().&quot;&lt;br /&gt;&quot;;
      echo db2_conn_errormsg().&quot;&lt;/p&gt;&quot;;
  }
  ?&gt;
  </code></pre>
  <p>Is there something I'm missing regarding the setup, that isn't documented anywhere?</p>
  <p>Best regards,
  Thomas</p>