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

Docker-php-apache-xdebug-gd-mysql-mysqli歷坑記
可以直接看最后的小結(jié)部分,之前的是做個記錄...

緣起

PHP & MySQL范例精解松捉,創(chuàng)建、修改酥诽、重用一書中,代碼用到的mysql_connect在5.5版本已經(jīng)廢棄,故改用php:5.4-apache

添加xdebug

找xdebug的對應(yīng)版本號

找對應(yīng)版本號失敗經(jīng)驗

  1. ?網(wǎng)上介紹的到xdebug站點,用phpinfo()的信息貼進(jìn)去,發(fā)現(xiàn),對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結(jié)果:

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

?最終,在https://github.com/xdebug/xdebug/tree/xdebug_2_4發(fā)現(xiàn)下面這句

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

又出現(xiàn)報錯

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 .

終于成功打出來了

運(yùn)行

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

復(fù)制到容器外

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

平時運(yùn)行

可以將各個文件夾映射加上

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坑

運(yùn)行網(wǎng)上一個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

發(fā)現(xiàn)

  'FreeType Support' => boolean false

添加Gd時,Dockerfile的內(nèi)容有部分要修改:

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

總結(jié)

加了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 .

運(yùn)行時:

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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末状囱,一起剝皮案震驚了整個濱河市尽超,隨后出現(xiàn)的幾起案子限府,更是在濱河造成了極大的恐慌读拆,老刑警劉巖祠肥,帶你破解...
    沈念sama閱讀 211,743評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件痢虹,死亡現(xiàn)場離奇詭異被去,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)奖唯,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,296評論 3 385
  • 文/潘曉璐 我一進(jìn)店門惨缆,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人丰捷,你說我怎么就攤上這事坯墨。” “怎么了病往?”我有些...
    開封第一講書人閱讀 157,285評論 0 348
  • 文/不壞的土叔 我叫張陵捣染,是天一觀的道長。 經(jīng)常有香客問我停巷,道長耍攘,這世上最難降的妖魔是什么榕栏? 我笑而不...
    開封第一講書人閱讀 56,485評論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮蕾各,結(jié)果婚禮上扒磁,老公的妹妹穿的比我還像新娘。我一直安慰自己示损,他們只是感情好渗磅,可當(dāng)我...
    茶點故事閱讀 65,581評論 6 386
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著检访,像睡著了一般。 火紅的嫁衣襯著肌膚如雪仔掸。 梳的紋絲不亂的頭發(fā)上脆贵,一...
    開封第一講書人閱讀 49,821評論 1 290
  • 那天,我揣著相機(jī)與錄音起暮,去河邊找鬼卖氨。 笑死,一個胖子當(dāng)著我的面吹牛负懦,可吹牛的內(nèi)容都是我干的筒捺。 我是一名探鬼主播,決...
    沈念sama閱讀 38,960評論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼纸厉,長吁一口氣:“原來是場噩夢啊……” “哼系吭!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起颗品,我...
    開封第一講書人閱讀 37,719評論 0 266
  • 序言:老撾萬榮一對情侶失蹤肯尺,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后躯枢,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體则吟,經(jīng)...
    沈念sama閱讀 44,186評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,516評論 2 327
  • 正文 我和宋清朗相戀三年锄蹂,在試婚紗的時候發(fā)現(xiàn)自己被綠了氓仲。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,650評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡得糜,死狀恐怖敬扛,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情掀亩,我是刑警寧澤舔哪,帶...
    沈念sama閱讀 34,329評論 4 330
  • 正文 年R本政府宣布,位于F島的核電站槽棍,受9級特大地震影響捉蚤,放射性物質(zhì)發(fā)生泄漏抬驴。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,936評論 3 313
  • 文/蒙蒙 一缆巧、第九天 我趴在偏房一處隱蔽的房頂上張望布持。 院中可真熱鬧,春花似錦陕悬、人聲如沸题暖。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,757評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽胧卤。三九已至,卻和暖如春拼岳,著一層夾襖步出監(jiān)牢的瞬間枝誊,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,991評論 1 266
  • 我被黑心中介騙來泰國打工惜纸, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留叶撒,地道東北人。 一個月前我還...
    沈念sama閱讀 46,370評論 2 360
  • 正文 我出身青樓耐版,卻偏偏與公主長得像祠够,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子粪牲,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,527評論 2 349