Docker-php-apache-xdebug-gd-mysql-mysqli历坑记
可以直接看最后的小结部分,之前的是做个记录…
缘起
PHP & MySQL范例精解,创建、修改、重用一书中,代码用到的mysql_connect在5.5版本已经废弃,故改用php:5.4-apache
添加xdebug
找xdebug的对应版本号
找对应版本号失败经验
-
❌网上介绍的到xdebug站点,用phpinfo()的信息贴进去,发现,对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结果:
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 jess