Docker PHP development environment configuration tutorial, dockerphp development tutorial

Source: Internet
Author: User
Tags php development environment

Docker PHP development environment configuration tutorial, dockerphp development tutorial

Preface

I use mac for development, but it is very inconvenient to install the php function that comes with mac, and it is inconsistent with the online linux development environment. The centos php development environment configured with vagrant has never been used before docker is used, but vagrant is no longer used since docker is available.

Configure your own php Image

First, create the following three files in any of your directories:

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 #====================================#configure the VM #-v default: /etc/nginx/sites-enabled/default # configure the program directory #-v web:/var/www/html # configure the ing port #-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 "]

Execute Command

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

Configure the php mysql Development Environment

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

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

Start a php test project

# Enable docker-compose up # disable docker-compose down

Summary

The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.