我试图用php7.1 docker创建一个开发环境。而且无论我出于何种原因尝试,它都说“驱动程序发生异常:找不到驱动程序
”。
我搜索了很多帖子,但找不到解决我问题的答案。
我正在使用以下dockerfile和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
建立步骤:
导航到网站symfony页面,我找不到驱动程序。转储PHP信息,我得到
然后,我创建了一个脚本,以从exec的“php -m”网址进行调用,并且var_dumps结果返回给我
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的 Angular 来看,pdo_mysql似乎确实已安装,但未启用。
奇怪的是,我有另一个使用symfony和几乎相同的docker config的项目,并且该项目有效。
有任何想法吗?
谢谢!
更新
原来,我包含的php.ini文件中的一些旧代码是apache使用的,而不是/ usr / local / etc / php中的正确代码,并且其中不包含pdo_mysql的必要配置。
最佳答案
试试这个。
使用以下任何一种方法找到您的php.ini文件。
<?php phpinfo(); ?>
<?php echo php_ini_loaded_file(); ?>
-将/ bin / bash放入您的容器并运行以下命令之一
php --ini
php -i | grep 'php.ini'
find / -name php.ini
从以下各行取消注释(删除;)
extension=pdo.so
extension=pdo_mysql.so
extension=pdo_sqlite.so
extension=mysql.so
保存,退出并运行
service apache2 restart
关于php - 找不到PHP docker pdo_mysql驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49521272/