Okay, so I’m trying to use docker to create a containerized php website that interacts with a postgresql database. Let’s use this website for reference:
https://www.shiphp.com/blog/2017/php-postgres-docker
Any php script that uses the function pg_connect() results in a fatal error:
Fatal error : Uncaught Error: Call to undefined function pg_connect() in /var/www/html/connect.php:4 Stack trace: #0 {main} thrown in /var/www/html/connect.php on line 4
This is my Dockerfile:
FROM php:apache
FROM postgres:latest
RUN apt-get update
RUN apt-get -y install curl
RUN apt-get -y install apache2
RUN apt-get -y install apache2-utils
RUN apt-get -y install postgresql
COPY index.html /var/www/html/
EXPOSE 80
EXPOSE 5432
There may be some unnecessary stuff in it or maybe missing something? I’m not really sure, but is there anyway that I can get the function to work? I cannot figure out how to install pdo_pgsql as when I attempt to do “apt-get install php-pgsql” it returns:
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package php-pgsql is a virtual package provided by:
php7.0-pgsql 7.0.33-0+deb9u3 [Not candidate version]
php7.3-pgsql 7.3.11-1~deb10u1 [Not candidate version]
E: Package ‘php-pgsql’ has no installation candidate
and trying to install one of those results in:
root@a60b9353291e:/var/www/html# apt-get install php7.0-pgsql 7.0.33-0+deb9u3
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package php7.0-pgsql is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package ‘php7.0-pgsql’ has no installation candidate
E: Unable to locate package 7.0.33-0+deb9u3
E: Couldn’t find any package by glob ‘7.0.33-0+deb9u3’
E: Couldn’t find any package by regex ‘7.0.33-0+deb9u3’
root@a60b9353291e:/var/www/html# apt-get install php7.3-pgsql 7.3.11-1~deb10u1
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package php7.3-pgsql is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package ‘php7.3-pgsql’ has no installation candidate
E: Unable to locate package 7.3.11-1~deb10u1
E: Couldn’t find any package by glob ‘7.3.11-1~deb10u1’
E: Couldn’t find any package by regex ‘7.3.11-1~deb10u1’
Sorry, I’m pretty new to this - what am I supposed to do to install the packages?
Any help would be appreciated, thank you.