[英]PHP docker pdo_mysql driver not found
我試圖用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信息,我得到
然后,我創建了一個腳本以從執行“ php -m”的url調用,然后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的角度來看,pdo_mysql似乎確實已安裝,但未啟用。
奇怪的是,我有另一個使用symfony和幾乎相同的docker config的項目,並且該項目有效。
有任何想法嗎?
謝謝!
UPDATE
原來,我包含的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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.