Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Adding PDO pdo_mysql Extension in Apache + PHP Docker Container

Tiempo de lectura: 2 minutos

Reading time: 2 minutes

Today I’m going to show you how to install the PDO pdo_mysql extension to use Codeigniter or RedBeans, etc…

We have the following docker-compose.yml file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
version: "3.1"
services:
miservicio_mariadb:
image: mariadb
container_name: mariadb_container
env_file:
- ./Dockerfile/mysql.env
environment:
MYSQL_DATABASE: "db_prueba"
MYSQL_USER: "user_prueba"
MYSQL_PASSWORD: "pass_mysql"
MYSQL_ROOT_PASSWORD: "contra@prueba"
volumes:
- ./config/mariadb:/var/lib/mysql
expose:
- 3306
ports:
- 3306:3306
networks:
- docker-network
phpmyadmin:
image: phpmyadmin
restart: always
container_name: phpmyadmin_container
ports:
- 8080:80
environment:
- PMA_ARBITRARY=1
links:
- miservicio_mariadb:db
networks:
- docker-network
miservicio_php:
build:
context: ./Dockerfile
dockerfile: php_file
env_file:
- ./Dockerfile/php.env
container_name: php_container
volumes:
- ./www:/var/www/html
- ./logs/apache:/var/log/apache2
- ./config/letsencrypt/certs:/etc/apache2/ssl/
- ./config/web/logs:/var/www/logs
expose:
- 80
- 443
ports:
- 8000:80
- 442:443
links:
- miservicio_mariadb
networks:
- docker-network
networks:
docker-network:
driver: bridge
external: true
version: "3.1" services: miservicio_mariadb: image: mariadb container_name: mariadb_container env_file: - ./Dockerfile/mysql.env environment: MYSQL_DATABASE: "db_prueba" MYSQL_USER: "user_prueba" MYSQL_PASSWORD: "pass_mysql" MYSQL_ROOT_PASSWORD: "contra@prueba" volumes: - ./config/mariadb:/var/lib/mysql expose: - 3306 ports: - 3306:3306 networks: - docker-network phpmyadmin: image: phpmyadmin restart: always container_name: phpmyadmin_container ports: - 8080:80 environment: - PMA_ARBITRARY=1 links: - miservicio_mariadb:db networks: - docker-network miservicio_php: build: context: ./Dockerfile dockerfile: php_file env_file: - ./Dockerfile/php.env container_name: php_container volumes: - ./www:/var/www/html - ./logs/apache:/var/log/apache2 - ./config/letsencrypt/certs:/etc/apache2/ssl/ - ./config/web/logs:/var/www/logs expose: - 80 - 443 ports: - 8000:80 - 442:443 links: - miservicio_mariadb networks: - docker-network networks: docker-network: driver: bridge external: true
version: "3.1"

services:
  miservicio_mariadb:
    image: mariadb
    container_name: mariadb_container
    env_file:
      - ./Dockerfile/mysql.env
    environment:
      MYSQL_DATABASE: "db_prueba"
      MYSQL_USER: "user_prueba"
      MYSQL_PASSWORD: "pass_mysql"
      MYSQL_ROOT_PASSWORD: "contra@prueba"
    volumes:
      - ./config/mariadb:/var/lib/mysql
    expose:
      - 3306
    ports:
      - 3306:3306
    networks:
      - docker-network
  phpmyadmin:
    image: phpmyadmin
    restart: always
    container_name: phpmyadmin_container
    ports:
      - 8080:80
    environment:
      - PMA_ARBITRARY=1
    links: 
      - miservicio_mariadb:db
    networks:
      - docker-network
  miservicio_php:
    build: 
      context: ./Dockerfile
      dockerfile: php_file
    env_file:
       - ./Dockerfile/php.env
    container_name: php_container
    volumes:
      - ./www:/var/www/html
      - ./logs/apache:/var/log/apache2
      - ./config/letsencrypt/certs:/etc/apache2/ssl/
      - ./config/web/logs:/var/www/logs
    expose:
      - 80
      - 443
    ports:
      - 8000:80
      - 442:443
    links: 
      - miservicio_mariadb
    networks:
      - docker-network
networks:
  docker-network:
    driver: bridge
    external: true

And the php_container file is created from this dockerfile:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# syntax=docker/dockerfile:1
FROM php:7.0-apache
RUN docker-php-ext-install mysqli
#Activate Apache modules:
RUN a2enmod headers
RUN a2enmod rewrite
RUN a2enmod ssl
RUN /etc/init.d/apache2 restart
# syntax=docker/dockerfile:1 FROM php:7.0-apache RUN docker-php-ext-install mysqli #Activate Apache modules: RUN a2enmod headers RUN a2enmod rewrite RUN a2enmod ssl RUN /etc/init.d/apache2 restart
# syntax=docker/dockerfile:1
FROM php:7.0-apache
RUN docker-php-ext-install mysqli

#Activate Apache modules:
RUN a2enmod headers
RUN a2enmod rewrite
RUN a2enmod ssl

RUN /etc/init.d/apache2 restart

If we want to install the pdo_mysql module, we have to add the following:

RUN docker-php-ext-install pdo_mysql

Resulting in the following dockerfile:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# syntax=docker/dockerfile:1
FROM php:7.0-apache
RUN docker-php-ext-install mysqli
RUN docker-php-ext-install pdo_mysql
#Activate Apache modules:
RUN a2enmod headers
RUN a2enmod rewrite
RUN a2enmod ssl
RUN /etc/init.d/apache2 restart
# syntax=docker/dockerfile:1 FROM php:7.0-apache RUN docker-php-ext-install mysqli RUN docker-php-ext-install pdo_mysql #Activate Apache modules: RUN a2enmod headers RUN a2enmod rewrite RUN a2enmod ssl RUN /etc/init.d/apache2 restart
# syntax=docker/dockerfile:1
FROM php:7.0-apache
RUN docker-php-ext-install mysqli

RUN docker-php-ext-install pdo_mysql

#Activate Apache modules:
RUN a2enmod headers
RUN a2enmod rewrite
RUN a2enmod ssl

RUN /etc/init.d/apache2 restart

And when we run phpinfo(); the installed module appears:

0

Leave a Comment