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)驗
?網(wǎng)上介紹的到xdebug站點,用phpinfo()的信息貼進(jìn)去,發(fā)現(xiàn),對5.6,5.4,5.3的都試過,都顯示不支持.
-
?
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