程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> Docker配置PHP開發環境教程,dockerphp開發教程

Docker配置PHP開發環境教程,dockerphp開發教程

編輯:關於PHP編程

Docker配置PHP開發環境教程,dockerphp開發教程


前言

筆者用的是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 "[email protected]" 

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

<?php
phpinfo(); 

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

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

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved