Docker PHP with pdo_pgsql install issue
Asked Answered
V

2

15

I'm very new to Docker and stepped into my first real project with it. We have a php app using Codeigniter and PostgreSQL and it works great. Now I'm trying to dockerize it and I've run into some troubles with the pdo_pgsql driver.

I found some help online to get the pdo_pgsql driver to install, however it was all out of date solutions for php-5x. What I have seemed to work because I checked the phpinfo page and my php.ini was loaded in correctly and says the pdo_pgsql and pgsql drivers are both installed and active????

Here is the error:

Strange thing is when I first hit the page I only get the first error. Then if I refresh the page the second error shows up.

When I log into the container and cd to the directory where it says the file does not exist, I can clearly see pdo.so,pdo_pgsql.so, and pgsql.so.

An Error Was Encountered

You have specified an invalid database connection group (dockerize) in your config/database.php file.

A PHP Error was encountered

Severity: Core Warning

Message: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20160303/pgsql' - /usr/local/lib/php/extensions/no-debug-non-zts-20160303/pgsql: cannot open shared object file: No such file or directory

Filename: Unknown

Here is the Dockerfile:

# Dockerfile
FROM php:7.1.12-apache

MAINTAINER Me <[email protected]>

COPY deploy/config/php.ini /usr/local/etc/php/
COPY target/myapp.tar.gz /var/www/html

RUN apt-get update

# Install Postgre PDO
RUN apt-get install -y libpq-dev \
    && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
    && docker-php-ext-install pdo pdo_pgsql pgsql

RUN tar -xzf /var/www/html/myapp.tar.gz \
    && cd /var/www/html \
    && rm -f myapp.tar.gz \
    && OLD_URL='http://localhost:8080' \
    && NEW_URL='http://dockerhost:8080' \
    && sed -i -e "s#$OLD_URL#$NEW_URL#" "/var/www/html/application/config/config.php"

EXPOSE 80
EXPOSE 443

Here is my docker-compose.yml:

version: "3"
services:
  app:
    image: me/myapp:v1
    build: .
    ports:
      - "8080:80"
      - "8043:443"
  postgres:
    image: postgres:9.6.6
    ports:
      - "5432:5432"

Here is my Codeigniter database.php:

This tries to connect to the Postgres in another container supposedly provided by the docker-compose with the above yml. I read a few places that said I simply use postgres as the host for the connection because the docker-compose.yml file has a service named postgres. This sounds kinda fishy to me, does this look right?

$active_group = "dockerize";
$query_builder = TRUE;
$db['dockerize'] = array(
        'dsn'       => 'pgsql:host=postgres;port=5432;dbname=mydb;user=postgres;password=postgres',
        'hostname' => 'postgres',
        'username' => 'postgres',
        'password' => 'postgres',
        'database' => 'mydb',
        'dbdriver' => 'pdo',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt'  => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
);

fyi: all the above is anonymized and slimmed down for readability

Vitavitaceous answered 2/12, 2017 at 0:42 Comment(0)
V
8

Oh dang I figured it all out. So everything I have above does work. Something weird was happening with how Docker was caching. I wasn't updating the image correctly I guess. I simply removed all containers and images and then rebuilt and ran it all and it just magically worked. Also had a couple of permissions issues on certain directories and files along the way.

Hope the above snips help someone, there is not a lot of docs on dockers php-apache image with pdo_pgsql.

Vitavitaceous answered 2/12, 2017 at 2:47 Comment(0)
R
2

if doesn't work, we can add :

RUN apt-get update && apt-get install -y apt-transport-https

(For https sources)

Retain answered 26/10, 2022 at 9:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.