相思资源网 Design By www.200059.com

前言

笔者用的是mac开发,但是mac自带的php功能安装十分不方便,并且和线上的linux开发环境不一致。在没有用docker之前一直用vagrant配置的centos的php开发环境,但是自从有了docker之后,就不再用vagrant了。

配置自己的php镜像

首先在自己的任意一个目录下创建如下三个文件

run.sh

#!/bin/bash
/usr/sbin/php-fpm7.0
/usr/sbin/nginx
tailf /etc/apt/sources.list

sources.list

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb 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.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"] 

执行命令

docker build -t d1studio:php-base:0.1 .

配置php mysql开发环境

mkdir -p ~/projects/php-app
cd ~/projects/php-app
mkdir mysql
mkdir www

www/index.php

<"htmlcode">
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;
 }
}

docker-compose.yml

version: '2'
services:
 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 up
#关闭
docker-compose down

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。

标签:
docker,php开发环境,docker配置开发环境

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“Docker配置PHP开发环境教程”

暂无Docker配置PHP开发环境教程的评论...

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?