前言
笔者用的是mac开发,但是mac自带的PHP功能安装十分不方便,并且和线上的linux开发环境不一致。在没有用docker之前一直用vagrant配置的centos的PHP开发环境,但是自从有了docker之后,就不再用vagrant了。
配置自己的PHP镜像
首先在自己的任意一个目录下创建如下三个文件
run.sh
PHP-fpm7.0
/usr/sbin/Nginx
tailf /etc/apt/sources.list
sources.list
Dockerfile
Nginx/sites-enabled/default
# 配置程序目录
# -v web:/var/www/html
# 配置映射端口
# -p 8008:80
# ===========================
MAINTAINER chengtao "751753158@qq.com"
ADD sources.list /etc/apt/sources.list
ADD run.sh /root/run.sh
RUN chmod +x /root/run.sh
RUN apt-get update
RUN apt-get install -y PHP-fpm PHP-MysqL Nginx
RUN sed -i 's/;date.timezone =/date.timezone = Asia\/Shanghai/' /etc/PHP/7.0/fpm/PHP.ini
RUN mkdir -p /run/PHP/
EXPOSE 80
CMD ["/bin/bash","/root/run.sh"]
执行命令
dio:PHP-base:0.1 .
配置PHP MysqL开发环境
www/index.PHP
Nginx.conf
PHP;
location / {
try_files $uri $uri/ =404;
}
location ~ \.PHP$ {
include snippets/fastcgi-PHP.conf;
fastcgi_pass unix:/run/PHP/PHP7.0-fpm.sock;
}
}
docker-compose.yml
MysqL:
image: MysqL:5.6
volumes:
- ./MysqL/:/var/lib/MysqL/
ports:
- "3307:3306"
environment:
- MysqL_ROOT_PASSWORD=123456
PHP-app:
image: d1studio/PHP-base:0.1
ports:
- "8009:80"
volumes:
- ./Nginx.conf:/etc/Nginx/sites-enabled/default
- ./www/:/var/www/html/
links:
- MysqL
开启PHP的测试项目
关闭
docker-compose down