前言
笔者用的是mac开发,但是mac自带的php功能安装十分不方便,并且和线上的linux开发环境不一致。在没有用docker之前一直用vagrant配置的centos的php开发环境,但是自从有了docker之后,就不再用vagrant了。
配置自己的php镜像
首先在自己的任意一个目录下创建如下三个文件
run.sh
#!/bin/bash/usr/sbin/php-fpm7.0/usr/sbin/nginxtailf /etc/apt/sources.list
sources.list
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricteddeb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-propertiesdeb http://mirrors.aliyun.com/ubuntu/ xenial main restricteddeb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-propertiesdeb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricteddeb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-propertiesdeb http://mirrors.aliyun.com/ubuntu/ xenial universedeb http://mirrors.aliyun.com/ubuntu/ xenial-updates universedeb http://mirrors.aliyun.com/ubuntu/ xenial multiversedeb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiversedeb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-propertiesdeb http://archive.canonical.com/ubuntu xenial partnerdeb-src http://archive.canonical.com/ubuntu xenial partnerdeb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricteddeb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-propertiesdeb http://mirrors.aliyun.com/ubuntu/ xenial-security universedeb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
Dockerfile
FROM ubuntu:16.04# ===========================# 配置虚拟主机# -v default:/etc/nginx/sites-enabled/default# 配置程序目录# -v web:/var/www/html# 配置映射端口# -p 8008:80# ===========================MAINTAINER chengtao "751753158@qq.com" ADD sources.list /etc/apt/sources.listADD run.sh /root/run.shRUN chmod +x /root/run.shRUN 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.iniRUN mkdir -p /run/php/EXPOSE 80 CMD ["/bin/bash","/root/run.sh"]
执行命令
docker build -t d1studio:php-base:0.1 .
配置php mysql开发环境
mkdir -p ~/projects/php-appcd ~/projects/php-appmkdir mysqlmkdir www
www/index.php
<?phpphpinfo();
nginx.conf
server { listen 80 default_server; root /var/www/html; index index.html index.htm index.php; location / { try_files $uri $uri/ =404; } location ~ /.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; }}
新闻热点
疑难解答