admin管理员组文章数量:1288987
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
- Ran docker-compose down --volumes to stop and remove containers.
- Used docker-compose up -d --build to rebuild the image with the Dockerfile.
- Accessed the container using docker exec -it apache-php bash and checked for the extensions with php -m.
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:
- Rewriting the Dockerfile to ensure dependencies are correctly installed.
- Adding phpinfo() to check PHP configuration (no mysqli or pdo_mysql in the output).
- Cleaning up old images using docker image prune -f and rebuilding everything from scratch.
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!
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
- Ran docker-compose down --volumes to stop and remove containers.
- Used docker-compose up -d --build to rebuild the image with the Dockerfile.
- Accessed the container using docker exec -it apache-php bash and checked for the extensions with php -m.
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:
- Rewriting the Dockerfile to ensure dependencies are correctly installed.
- Adding phpinfo() to check PHP configuration (no mysqli or pdo_mysql in the output).
- Cleaning up old images using docker image prune -f and rebuilding everything from scratch.
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!
Share Improve this question asked Jan 23 at 20:05 JasoguJasogu 11 Answer
Reset to default 0You 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
本文标签: Cannot install mysqli or pdomysql extensions in PHP 7433 Docker containerStack Overflow
版权声明:本文标题:Cannot install mysqli or pdo_mysql extensions in PHP 7.4.33 Docker container - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738468244a2088429.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论