Reputation: 1
I’m trying to set up a Docker-based environment for my PHP 7.4.33 application, but I’m unable to install the mysqli and pdo_mysql extensions. Despite following several tutorials and rebuilding the image multiple times, the extensions are not being installed.
Here’s my setup:
Dockerfile
FROM php:7.4.33-apache
# Install necessary extensions
RUN apt-get update && apt-get install -y \
libmariadb-dev \
&& docker-php-ext-install mysqli pdo pdo_mysql
WORKDIR /var/www/html
docker-compose.yml
version: '3.8'
services:
apache-php:
build:
context: /home/jasogu/docker/lamp-stack
dockerfile: Dockerfile
container_name: apache-php
ports:
- "8080:80"
volumes:
- ./www:/var/www/html
- ./php-config:/usr/local/etc/php
networks:
- lamp-network
depends_on:
- mysql
mysql:
image: mysql:8.0
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: "password"
MYSQL_DATABASE: "database"
MYSQL_USER: "user"
MYSQL_PASSWORD: "password"
volumes:
- ./mysql-data:/var/lib/mysql
networks:
- lamp-network
phpmyadmin:
image: phpmyadmin:latest
container_name: phpmyadmin
environment:
PMA_HOST: mysql
PMA_USER: "user"
PMA_PASSWORD: "password"
ports:
- "8081:80"
networks:
- lamp-network
depends_on:
- mysql
volumes:
mysql-data:
networks:
lamp-network:
Steps I followed
What I see: When I run php -m | grep mysqli or php -m | grep pdo_mysql, there’s no output, meaning the extensions are not installed.
What I tried:
Error logs: When checking the logs, I don’t see any explicit errors about missing extensions or failed installations.
Question How can I successfully install the mysqli and pdo_mysql extensions in my PHP 7.4.33 container? Is there anything wrong with my Dockerfile or docker-compose.yml? Any help would be greatly appreciated!
Upvotes: 0
Views: 44
Reputation: 573
You also have to enable
the extensions. Try something like this in your Dockerfile and rebuild the image:
FROM php:7.4.33-apache
# Install necessary extensions
RUN apt-get update && apt-get install -y \
libmariadb-dev \
&& docker-php-ext-install mysqli pdo pdo_mysql \
&& docker-php-ext-enable mysqli pdo pdo_mysql # add this line
WORKDIR /var/www/html
Upvotes: 0