找不到PHP docker pdo_mysql驱动程序
我正在尝试使用php7.1 docker创建一个开发环境.而且无论我出于何种原因尝试,它都说驱动程序中发生异常:找不到驱动程序 "
Im trying create a dev environment with php7.1 docker. And no matter what I try for some reason it says "An exception occured in driver: could not find driver ".
我搜索了很多帖子,但找不到解决我问题的答案.
I have searched through a lot of posts but have found no answer that solves my problem.
我正在使用以下dockerfile和docker-compose.yml:
I am using the following dockerfile and docker-compose.yml:
FROM php:7.1-apache
COPY dockerConfig/php.ini /usr/local/etc/php/
RUN apt-get update \
&& apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng12-dev \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd
# Install MCrypt
RUN apt-get update \
&& apt-get install -y libmcrypt-dev \
&& docker-php-ext-install mcrypt
# Install Intl
RUN apt-get update \
&& apt-get install -y libicu-dev \
&& docker-php-ext-install intl
# Install Mysql
RUN docker-php-ext-install pdo pdo_mysql
# Install opcache
RUN docker-php-ext-install opcache
# Configure Apache Document Root
ENV APACHE_DOC_ROOT /var/www/html
# Enable Apache mod_rewrite
RUN a2enmod rewrite
COPY dockerConfig/mysite.local.conf /etc/apache2/sites-available/mysite.local.conf
RUN a2ensite mysite.local.conf
RUN a2dissite 000-default.conf
COPY / /var/www/html
RUN service apache2 restart
version: '3'
services:
mysite-web:
networks:
mysite:
ipv4_address: 178.17.10.3
build:
context: .
dockerfile: Dockerfile
volumes:
- $PWD:/var/www/html
container_name: mysite-dev-running
networks:
mysite:
driver: bridge
ipam:
config:
- subnet: 178.17.10.0/24
构建步骤:
- docker image rm(手动删除所有图像)
- docker rm xxxxx(手动删除所有容器)
- docker-compose build --no-cache
- docker-compose up -d
导航到网站symfony页面,但找不到驱动程序.转储PHP信息,我得到
Navigate to web site symfony page and I get driver not found. Dump php info and I get
然后我创建了一个脚本,以从exec的"php -m"网址进行调用,并var_dumps结果给了我
Then I created a script to call from a url that exec's "php -m" and var_dumps the result which gives me
array(42) { [0]=> string(13) "[PHP Modules]" [1]=> string(4) "Core" [2]=> string(5) "ctype" [3]=> string(4) "curl" [4]=> string(4) "date" [5]=> string(3) "dom" [6]=> string(8) "fileinfo" [7]=> string(6) "filter" [8]=> string(3) "ftp" [9]=> string(2) "gd" [10]=> string(4) "hash" [11]=> string(5) "iconv" [12]=> string(4) "intl" [13]=> string(4) "json" [14]=> string(6) "libxml" [15]=> string(8) "mbstring" [16]=> string(6) "mcrypt" [17]=> string(7) "mysqlnd" [18]=> string(7) "openssl" [19]=> string(4) "pcre" [20]=> string(3) "PDO" [21]=> string(9) "pdo_mysql" [22]=> string(10) "pdo_sqlite" [23]=> string(4) "Phar" [24]=> string(5) "posix" [25]=> string(8) "readline" [26]=> string(10) "Reflection" [27]=> string(7) "session" [28]=> string(9) "SimpleXML" [29]=> string(3) "SPL" [30]=> string(7) "sqlite3" [31]=> string(8) "standard" [32]=> string(9) "tokenizer" [33]=> string(3) "xml" [34]=> string(9) "xmlreader" [35]=> string(9) "xmlwriter" [36]=> string(12) "Zend OPcache" [37]=> string(4) "zlib" [38]=> string(0) "" [39]=> string(14) "[Zend Modules]" [40]=> string(12) "Zend OPcache" [41]=> string(0) "" }
因此,从apache的角度来看,pdo_mysql似乎确实已安装,但未启用.
So pdo_mysql does seem to be installed from apache's perspective, but somehow not enabled.
奇怪的是,我有另一个项目使用symfony和几乎相同的docker config,并且可以正常工作.
What is strange is that I have another project that uses symfony and almost identical docker config and that one works.
有什么想法吗?
谢谢!
更新
事实证明,我所包含的php.ini文件中的一些旧代码是apache使用的,而不是/usr/local/etc/php中的正确代码,并且其中不包含pdo_mysql的必要配置.
It turns out some of the legacy code I had contained a php.ini file apache was using that one instead of the proper one in /usr/local/etc/php and that one did not contain the necessary configuration with pdo_mysql.
尝试一下. 使用以下任何一种方法找到您的php.ini文件.
Try this. Find your php.ini file using any of these methods.
<?php phpinfo(); ?>
<?php echo php_ini_loaded_file(); ?>
-或/bin/bash进入容器并运行以下命令之一
-- OR /bin/bash into your container and run one of these commands
php --ini
php -i | grep 'php.ini'
find / -name php.ini
在以下几行中取消注释(删除;);
Uncomment (remove the ;) from the following lines
extension=pdo.so
extension=pdo_mysql.so
extension=pdo_sqlite.so
extension=mysql.so
保存,退出并运行
service apache2 restart