docker的官方php镜像php:5.4-apache配置xdebug-gd-mysql-mysqli

Docker-php-apache-xdebug-gd-mysql-mysqli历坑记
可以直接看最后的小结部分,之前的是做个记录...

缘起

PHP & MySQL范例精解,创建、修改、重用一书中,代码用到的mysql_connect在5.5版本已经废弃,故改用php:5.4-apache

添加xdebug

找xdebug的对应版本号

找对应版本号失败经验

  1. ❌网上介绍的到xdebug站点,用phpinfo()的信息贴进去,发现,对5.6,5.4,5.3的都试过,都显示不支持.

  2. pecl search xdebug

    # pecl search xdebug
    Package Stable/(Latest) Local
    xdebug  2.9.4 (stable)        Provides functions for function traces and profiling
    

    尝试2.9.4结果:

    pecl/xdebug requires PHP (version >= 7.1.0), installed version is 5.4.45
    

✅最终,在https://github.com/xdebug/xdebug/tree/xdebug_2_4发现下面这句

Restrict Xdebug 2.4 to PHP >= 5.4 and PHP < 7.1

打出镜像

Dockerfile

FROM php:5.4-apache
COPY Dockerfile /
RUN pecl channel-update pecl.php.net && \
        pecl install xdebug-2.4.1 && \
        docker-php-ext-enable xdebug && \
        mv /Dockerfile /Dockerfile.php-5.4-apache-xdebug
# mkdir Dockerfile.php-5.4-apache-xdebug && cd Dockerfile.php-5.4-apache-xdebug
# docker build -t php-5.4-apache-xdebug .

终于可以打出镜像

初步添加mlocate和gd

查看版本及替换源

查看容器里的debian版本是jessie

# cat /etc/apt/sources.list
deb http://httpredir.debian.org/debian jessie main
deb http://httpredir.debian.org/debian jessie-updates main
deb http://security.debian.org jessie/updates main

替换源为阿里的

mv /etc/apt/sources.list /etc/apt/sources.list.bak
echo "deb http://mirrors.aliyun.com/debian jessie main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb-src http://mirrors.aliyun.com/debian jessie main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb http://mirrors.aliyun.com/debian jessie-updates main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb-src http://mirrors.aliyun.com/debian jessie-updates main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb-src http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free" >> /etc/apt/sources.list &&\

尝试Dockerfile失败:

这个可以跳过不看,作个记录...

FROM php-5.4-apache-xdebug
COPY Dockerfile /
RUN mv /Dockerfile /Dockerfile.php-5.4-apache-xdebug-mlocate-gd && \
mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
echo "deb http://mirrors.aliyun.com/debian jessie main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb-src http://mirrors.aliyun.com/debian jessie main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb http://mirrors.aliyun.com/debian jessie-updates main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb-src http://mirrors.aliyun.com/debian jessie-updates main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb-src http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free" >> /etc/apt/sources.list &&\
apt-get update && apt-get install -y mlocate \
                                     libfreetype6-dev \
                                     libjpeg62-turbo-dev \
                                     libpng-dev && \
docker-php-ext-configure gd --with-freetype --with-jpeg && \
docker-php-ext-install -j$(nproc) gd


# mkdir Dockerfile.php-5.4-apache-xdebug-mlocate-gd && cd Dockerfile.php-5.4-apache-xdebug-mlocate-gd
# docker build -t php-5.4-apache-xdebug-mlocate-gd .

错误返回:

W: There is no public key available for the following key IDs:
AA8E81B4331F7F50
解决的办法为:
apt-get install debian-keyring debian-archive-keyring
然后
apt-key update

查自 https://www.cnblogs.com/lege/p/4508736.html

又出现报错

configure: WARNING: unrecognized options: --with-freetype, --with-jpeg
error: /usr/src/php/ext/-j6 does not exist

usage: /usr/local/bin/docker-php-ext-install ext-name [ext-name ...]
   ie: /usr/local/bin/docker-php-ext-install gd mysqli
       /usr/local/bin/docker-php-ext-install pdo pdo_mysql

-j$(nproc)去除,

成功打出镜像

Dockerfile

FROM php-5.4-apache-xdebug
COPY Dockerfile /
RUN mv /Dockerfile /Dockerfile.php-5.4-apache-xdebug-mlocate-gd && \
mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
echo "deb http://mirrors.aliyun.com/debian jessie main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb-src http://mirrors.aliyun.com/debian jessie main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb http://mirrors.aliyun.com/debian jessie-updates main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb-src http://mirrors.aliyun.com/debian jessie-updates main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb-src http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free" >> /etc/apt/sources.list &&\
apt-get update && \
apt-get install -y --assume-yes  debian-keyring debian-archive-keyring apt-utils && apt-key update 

RUN apt-get install -y  mlocate \
                                     libfreetype6-dev \
                                     libjpeg62-turbo-dev \
                                     libpng-dev && \
docker-php-ext-configure gd --with-freetype --with-jpeg && \
docker-php-ext-install gd
# mkdir Dockerfile.php-5.4-apache-xdebug-mlocate-gd && cd Dockerfile.php-5.4-apache-xdebug-mlocate-gd
# docker build -t php-5.4-apache-xdebug-mlocate-gd .

终于成功打出来了

运行

docker run -d \
           -p 80:80 \
           --name virhuiai-php-7302195625-ch1tmp \
           --net=virhuiai_nw \
           -v /Users/jjkkll/Documents/2020-book-read/7302195625/9780470192429_All_Code/ch_01/public_files/:/var/www/html/ \
           -v /Users/jjkkll/Documents/2020-book-read/7302195625/9780470192429_All_Code/ch_01/lib/:/var/www/lib \
           -v /Users/jjkkll/Documents/2020-book-read/7302195625/9780470192429_All_Code/ch_01/templates/:/var/www/templates \
           -v /Users/jjkkll/Documents/2020-book-read/7302195625/docker/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
php-5.4-apache-xdebug-mlocate-gd
docker cp virhuiai-php-7302195625-ch1tmp:/etc/apache2/apache2.conf /Volumes/TmpDownload/

使用临时方式,找下xdebug的位置

docker run -d \
           -p 80:80 \
           --rm \
           --name virhuiai-php-7302195625-ch01 \
           --net=virhuiai_nw \
php-5.4-apache-xdebug-mlocate-gd
# locate xdebug
locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
# updatedb

# # locate xdebug
/Dockerfile.php-5.4-apache-xdebug
/Dockerfile.php-5.4-apache-xdebug-mlocate-gd
/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
/usr/local/lib/php/.registry/.channel.pecl.php.net/xdebug.reg
/usr/local/lib/php/doc/xdebug
/usr/local/lib/php/doc/xdebug/CREDITS
/usr/local/lib/php/doc/xdebug/LICENSE
/usr/local/lib/php/doc/xdebug/README.rst
/usr/local/lib/php/doc/xdebug/contrib
/usr/local/lib/php/doc/xdebug/contrib/tracefile-analyser.php
/usr/local/lib/php/doc/xdebug/contrib/xt.vim
/usr/local/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so

找到位置

/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

复制到容器外

docker cp virhuiai-php-7302195625-ch01:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /Users/jjkkll/Documents/2020-book-read/7302195625/

修改

/Users/jjkkll/Documents/2020-book-read/7302195625/docker-php-ext-xdebug-4php54apache.ini
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so
xdebug.remote_enable = On
xdebug.remote_handler = dbgp
xdebug.remote_host = host.docker.internal 
xdebug.remote_port = 9001
xdebug.remote_log = /var/log/php/xdebug.log

平时运行

可以将各个文件夹映射加上

docker run -d \
           -p 80:80 \
           --rm \
           --name virhuiai-php-7302195625-ch01 \
           --net=virhuiai_nw \
           -v /Users/jjkkll/Documents/2020-book-read/7302195625/9780470192429_All_Code/ch_01/public_files/:/var/www/html/ \
           -v /Users/jjkkll/Documents/2020-book-read/7302195625/9780470192429_All_Code/ch_01/lib/:/var/www/lib \
           -v /Users/jjkkll/Documents/2020-book-read/7302195625/9780470192429_All_Code/ch_01/templates/:/var/www/templates \
           -v /Users/jjkkll/Documents/2020-book-read/7302195625/docker/docker-php-ext-xdebug-4php54apache.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
-v /Users/jjkkll/Documents/2020-book-read/7302195625/docker/apache2-4php54apache.conf:/etc/apache2/apache2.conf \
php-5.4-apache-xdebug-mlocate-gd

添加mysqli

Dockerfile.php-5.4-apache-xdebug-mlocate-gd-mysqli
php-5.4-apache-xdebug-mlocate-gd-mysqli

Dockerfile

FROM php-5.4-apache-xdebug-mlocate-gd
COPY Dockerfile /
RUN mv /Dockerfile /Dockerfile.php-5.4-apache-xdebug-mlocate-gd-mysqli && \
# apt-get install php5-mysql 
docker-php-ext-install mysql mysqli
# mkdir Dockerfile.php-5.4-apache-xdebug-mlocate-gd-mysqli && cd Dockerfile.php-5.4-apache-xdebug-mlocate-gd-mysqli
# docker build -t php-5.4-apache-xdebug-mlocate-gd-mysqli .

打出镜像

docker run -d \
           -p 80:80 \
           --rm \
           --name virhuiai-php-7302195625-ch01 \
           --net=virhuiai_nw \
           -v /Users/jjkkll/Documents/2020-book-read/7302195625/9780470192429_All_Code/ch_01/public_files/:/var/www/html/ \
           -v /Users/jjkkll/Documents/2020-book-read/7302195625/9780470192429_All_Code/ch_01/lib/:/var/www/lib \
           -v /Users/jjkkll/Documents/2020-book-read/7302195625/9780470192429_All_Code/ch_01/templates/:/var/www/templates \
           -v /Users/jjkkll/Documents/2020-book-read/7302195625/docker/docker-php-ext-xdebug-4php54apache.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
-v /Users/jjkkll/Documents/2020-book-read/7302195625/docker/apache2-4php54apache.conf:/etc/apache2/apache2.conf \
php-5.4-apache-xdebug-mlocate-gd-mysqli

gd坑

运行网上一个gd例子报错:

Call to undefined function imagettftext()

查看gd_info():

var_dump(gd_info());
array (size=11)
  'GD Version' => string 'bundled (2.1.0 compatible)' (length=26)
  'FreeType Support' => boolean false
  'T1Lib Support' => boolean false
  'GIF Read Support' => boolean true
  'GIF Create Support' => boolean true
  'JPEG Support' => boolean false
  'PNG Support' => boolean true
  'WBMP Support' => boolean true
  'XPM Support' => boolean false
  'XBM Support' => boolean true
  'JIS-mapped Japanese Font Support' => boolean false

发现

  'FreeType Support' => boolean false

添加Gd时,Dockerfile的内容有部分要修改:

docker-php-ext-configure gd --with-freetype-dir=/usr/include/freetype2 --with-jpeg-dir=/usr/include/ --with-freetype --with-jpeg --enable-gd-native-ttf && docker-php-ext-install gd

总结

加了xdebug镜像的Dockerfile

FROM php:5.4-apache
COPY Dockerfile /
RUN pecl channel-update pecl.php.net && \
        pecl install xdebug-2.4.1 && \
        docker-php-ext-enable xdebug && \
        mv /Dockerfile /Dockerfile.php-5.4-apache-xdebug
# mkdir Dockerfile.php-5.4-apache-xdebug && cd Dockerfile.php-5.4-apache-xdebug
# docker build -t php-5.4-apache-xdebug .

加了gd的镜像的Dockerfile

FROM php-5.4-apache-xdebug
COPY Dockerfile /
RUN mv /Dockerfile /Dockerfile.php-5.4-apache-xdebug-mlocate-gd && \
mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
echo "deb http://mirrors.aliyun.com/debian jessie main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb-src http://mirrors.aliyun.com/debian jessie main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb http://mirrors.aliyun.com/debian jessie-updates main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb-src http://mirrors.aliyun.com/debian jessie-updates main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free" >> /etc/apt/sources.list &&\
echo "deb-src http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free" >> /etc/apt/sources.list &&\
apt-get update && \
apt-get install -y --assume-yes  debian-keyring debian-archive-keyring apt-utils && apt-key update 

RUN apt-get install -y  mlocate \
                                     libfreetype6-dev \
                                     libjpeg62-turbo-dev \
                                     libpng-dev && \
docker-php-ext-configure gd --with-freetype --with-freetype-dir=/usr/include/freetype2 --with-jpeg --with-jpeg-dir=/usr/include/ --enable-gd-native-ttf && docker-php-ext-install gd
#docker-php-ext-install -j$(nproc) gd
# mkdir Dockerfile.php-5.4-apache-xdebug-mlocate-gd && cd Dockerfile.php-5.4-apache-xdebug-mlocate-gd
# docker build -t php-5.4-apache-xdebug-mlocate-gd .

加了mysql,mysqli的镜像的Dockerfile

FROM php-5.4-apache-xdebug-mlocate-gd
COPY Dockerfile /
RUN mv /Dockerfile /Dockerfile.php-5.4-apache-xdebug-mlocate-gd-mysqli && \
# apt-get install php5-mysql 
docker-php-ext-install mysql mysqli
# mkdir Dockerfile.php-5.4-apache-xdebug-mlocate-gd-mysqli && cd Dockerfile.php-5.4-apache-xdebug-mlocate-gd-mysqli
# docker build -t php-5.4-apache-xdebug-mlocate-gd-mysqli .

运行时:

docker run -d \
           -p 80:80 \
           --name virhuiai-php-fzyz54 \
           --net=virhuiai_nw \
           -v /..省略长目录./fzyz/webapps/:/var/www/html/ \
           -v /..省略长目录./fzyz/sitedata/:/var/www/sitedata/ \
           -v /..省略长目录./fzyz/miniphp/:/var/www/miniphp/ \
           -v /..省略长目录./docker-php-ext-xdebug-4php54apache.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
           -v /..省略长目录./apache2-4php54apache.conf:/etc/apache2/apache2.conf \
php-5.4-apache-xdebug-mlocate-gd-mysqli
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,444评论 6 496
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,421评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 160,036评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,363评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,460评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,502评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,511评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,280评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,736评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,014评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,190评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,848评论 5 338
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,531评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,159评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,411评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,067评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,078评论 2 352