Docker Community Forums

Share and learn in the Docker community.

How to run phpinfo() from my apache container?

I am trying to get a connection from my container to AWS Postresql. So I need to modify my php.ini to load the Postgresql driver in php.ini. To see if my method for loading the driver is working I need to run phpinfo() from inside the container. I was told to run interactive php from the host’s cli but I think that will run on the host’s php.ini rather than the containers php.ini (they are different)).

How can I run phpinfo() in the container?

It does not exist at all, which means php will run the default options.

Look at your docker file, it starts from a “clean” OS, installs Apache and PHP in it. But it never copies the php.ini file from the PHP installation into /usr/local/etc/php. Actually in lines 31 and 32 it creates the conf.d directory but that is it.

So I would suggest, at the end of your docker file, add code to copy php.ini-production to /usr/local/etc/php.ini, and edits as required. Or use default options.

Thanks lewish. I am not sure where you are getting these line numbers from? In light of the below, where should I place the copy of the php.ini? As you can see in the Dockerfile, I am appending the “modifications” to the default php.ini in the container. But the two last lines that try to do the same thing with the “extension=pgp_pdo_pgsql.so” don’t seem to be working.

Here is the Dockerfile:
FROM bitnami/php-fpm:7.2 as builder
RUN install_packages git autoconf build-essential
WORKDIR /app
RUN wget https://github.com/xdebug/xdebug/archive/2.6.0.tar.gz &&
tar xzf 2.6.0.tar.gz &&
cd xdebug-2.6.0 &&
phpize &&
./configure --enable-xdebug &&
make && make install

FROM bitnami/php-fpm:7.2
COPY --from=builder /opt/bitnami/php/lib/php/extensions/xdebug.so /opt/bitnami/php/lib/php/extensions/
RUN echo ‘zend_extension="/opt/bitnami/php/lib/php/extensions/xdebug.so"’ >> /opt/bitnami/php/etc/php.ini

RUN echo “xdebug.remote_port=9000” >> /opt/bitnami/php/etc/php.ini
&& echo “xdebug.remote_enable=1” >> /opt/bitnami/php/etc/php.ini
&& echo “xdebug.remote_connect_back=0” >> /opt/bitnami/php/etc/php.ini
&& echo “xdebug.remote_host=192.168.122.1” >> /opt/bitnami/php/etc/php.ini
&& echo “xdebug.idekey=docker” >> /opt/bitnami/php/etc/php.ini
&& echo “xdebug.remote_autostart=1” >> /opt/bitnami/php/etc/php.ini
&& echo “xdebug.remote_log=/tmp/xdebug.log” >> /opt/bitnami/php/etc/php.ini
&& echo “extension=pgp_pdo_pgsql.so” >> /opt/bitnami/php/etc/php.ini
&& echo “extension==pgp_pgsql.so” >> /opt/bitnami/php/etc/php.ini

and here is the docker-compose:
version: ‘3’

services:

apache:
image: bitnami/apache:latest
restart: unless-stopped
ports:

  • 80:8080
    volumes:
  • ./apache/app.conf:/vhosts/app.conf:ro
  • ./app:/app
    networks:
  • net

mysql:
container_name: “mysql”
restart: unless-stopped
image: mysql:5.6
environment:

  • MYSQL_DATABASE
  • MYSQL_PASSWORD
  • MYSQL_ROOT_PASSWORD
  • MYSQL_USER
    volumes:
  • data:/var/lib/mysql
  • ./mysql/mysql.sql:/docker-entrypoint-initdb.d/mysql.sql
    ports:
  • “3306:3306”
    networks:
  • net

phpmyadmin:
container_name: phpmyadmin
restart: unless-stopped
image: phpmyadmin/phpmyadmin
environment:

  • PMA_HOST=mysql
  • PMA_PORT=3306
    ports:
  • “8081:80”
    networks:
  • net

php-fpm:
build: ./php
restart: unless-stopped
image: bitnami/php-fpm
volumes:

  • ./app:/app
    environment:
  • XDEBUG_CONFIG=“remote_host=192.168.122.1”
    networks:
  • net

jasperreports:
image: ‘bitnami/jasperreports:7’
restart: unless-stopped
environment:

  • MARIADB_HOST=mysql
  • MARIADB_PORT_NUMBER=3306
  • JASPERREPORTS_USERNAME=admin
  • JASPERREPORTS_PASSWORD=bitnami
  • JASPERREPORTS_DATABASE_USER=admin
  • JASPERREPORTS_DATABASE_PASSWORD=xxx
  • JASPERREPORTS_DATABASE_NAME=jasper
  • ALLOW_EMPTY_PASSWORD=yes
    ports:
  • ‘8080:8080’
    volumes:
  • jasperreports_data:/bitnami
    depends_on:
  • mysql
    networks:
  • net

volumes:
data:
driver: local
jasperreports_data:
driver: local
networks:
net:

See this article for some good advice on this kind of multiple container implementation:

One more piece you may need is to move the php-fpm port away from the xdebug port in your php-fpm Dockerfile:
RUN sed -i ‘s/9000/8090/’ /usr/local/etc/php-fpm.d/zz-docker.conf
Then you would need to use port 8090 in the apache configuration for the virtual host rather than 9000.