PHP7 development environment based on Docker deployment

Source: Internet
Author: User
Tags fpm php development environment virtualbox shared folder docker ps docker run docker toolbox docker machine

Why use Docker
    • One place to compile, to use everywhere
    • Easy migration, regardless of hosting environment
    • Environment and host isolation
    • Rapid deployment of the development environment

A very common scenario: after changing the computer, each time you need to reinstall the PHP development environment, wasting a lot of time. With Docker, you just have to compile it beforehand, and you don't need to compile it again, and even if you switch from Windows to Mac and Linux, our compiled environment can still be used: just import or pull down.

Environmental requirements
    • Docker (Windows uses Dockertoolbox instead)
    • Git

Dockertoolbox integrates Git, VirtualBox, docker-machine.

Installing Docker

Official:
Https://store.docker.com/search?type=edition&offering=community

Installation on Unix/linux

Docker requires an Ubuntu system with a kernel version of more than 3.10 to view your current kernel version via the UNAME-R command:

[[email protected] ~]#  uname -r3.10.0-327.22.2.el7.x86_64

Docker supports the following CentOS versions:

    • CentOS 7 (64-bit)
    • CentOS 6.5 (64-bit) or later

Docker supports the following Ubuntu versions:

    • Ubuntu precise 12.04 (LTS)
    • Ubuntu trusty 14.04 (LTS)
    • Ubuntu Wily 15.10
    • Other updated versions ...
curl -fsSL https://get.docker.com/ | sh# daocloud.io 国内镜像curl -sSL https://get.daocloud.io/docker | sh

This installation package is available for most major Linux distributions such as Ubuntu,debian,centos.

CENTOS7 support for installing with Yum:

yum updateyum install docker

View version after installation:

docker version

To start the Docker service:

service docker start # 或者systemctl start docker

CENTOS7 uses SYSTEMCTL to replace service management services.

Install on Windows

WINDOWS10 Pro/Enterprise Edition can be downloaded: Https://download.docker.com/win/stable/Docker%20for%20Windows%20Installer.exe.

Other versions need to be used: Docker toolbox:https://docs.docker.com/toolbox/overview/. A virtual machine is actually installed.

Dockertoolbox:https://download.docker.com/win/stable/dockertoolbox.exe

Follow the prompts to install.

Install complete open Dockertoolbox, or open the git bash command line:

$ docker-machine create --driver=virtualbox defaultRunning pre-create checks...(default2) No default Boot2Docker ISO found locally, downloading the latest release...(default2) Latest release for github.com/boot2docker/boot2docker is v18.01.0-ce(default2) Downloading C:\Users\YJC\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.01.0-ce/boot2docker.iso...

When you create machine, go back boot2docker.iso to check for presence, cache location: C:\Users\YJC\.docker\machine\cache . YJCis the user name of the PC, whichever is the actual. boot2docker.isothe download will be slow, about 45M in size. It can be downloaded in advance by other means and placed in the directory.

Latest boot2docker.iso : Https://github.com/boot2docker/boot2docker/releases/download/v18.01.0-ce/boot2docker.iso.
To facilitate the download, the network disk also saved a copy: Link: https://pan.baidu.com/s/1i6QGIg9 Password: FSMB

If nothing goes wrong, you can get into the Docker Linux in this virtual machine:

$ docker-machine Start defaultstarting "Default" ... (default) Check network to re-create if needed ... (default) Waiting for an IP ... Machine "Default" is started. Waiting for SSH to be available ... Detecting the Provisioner ... Waiting for SSH to be available ... Detecting the Provisioner ... Restarted machines May has the new IP addresses.                         Need to re-run the ' Docker-machine env ' command.$ docker-machine lsname ACTIVE DRIVER State URL           SWARM DOCKER Errorsdefault-virtualbox Running tcp://192.168.99.101:2376  Unknown Unable to query Docker Version:get Https://192.168.99.101:2376/v1.15/version:x509:certificate are valid for                  192.168.99.100, not 192.168.99.101$ docker-machine ssh default # #. ## ## ##        ==               ## ## ## ## ##    ===           /"""""""""""""""""\___/ ===      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~  ~ ~/===-~ ~ ~ \______ o __/\  \         __/              \____\_______/ _                 _   ____     _            _| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|| |_) | (_) | (_) | |_ / __/ (_| | (_) |   (__| < __/| | _.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_| Boot2docker version 18.01.0-ce, build Head:0bb7bbd-thu Jan 16:32:39 UTC 2018Docker version 18.01.0-ce, build 03596f 5[email protected]:~$

Docker-machine command:

Commands:active print which machine was active config Print the connection config for Mach INE create create a machine env Display the commands to set up the environment for the Docker Client Inspect inspect information about a machine IP Get the IP address of a MA Chine kill kill a machine LS List machines provision re-provision exist                     ing machines Regenerate-certs regenerate TLS certificates for a machine restart restart a machine RM  Remove a machine ssh Log to or run a command on a machine with SSH. SCP Copy files between machines start start a machine status Get the St ATUs of a machine stop stop a machine upgrade upgrade a machine to the latest version of Docker url Get the URL of a machine version Show the Docker machine version or a machine Docker version help Shows a list of commands or help for one command

We recommend that you open VirtualBox to the default configuration shared directory:

It is configured by default c/Users .

Configuration options: Auto mount, fixed assignment.

If you need to mount the directory manually:

mount -t vboxsf www /data

/datais a mount point inside the container.

Deploying a development environment using Php71-fpm-centos68-phalcon-withext

For ease of use, I have php7.1+fpm+nginx+phalcon compiled the image of the development environment. Based on a self-compiled php71-fpm-centos68 image, the parent image is centos:6.8 .

Note: php71-fpm-centos68-phalcon-withext As with the php71-fpm-centos68-phalcon function, just the PHP extension is copied directly to the image php71-fpm-centos68-phalcon compiled so file into the mirror, eliminating the process of compilation, and save space ( php71-fpm-centos68 800M, php71-fpm-centos68-phalcon 1.4G, php71-fpm-centos68-phalcon-withext 831M).

php7.1-phalconThe development environment includes:

    • CentOS 6.8
    • PHP 7.1.12
    • php-fpm
    • Nginx 1.12.2
    • Redis 3.2.6

Included PHP additional extensions:

    • Swoole 1.10.1
    • Phpredis 3.0.0
    • Yac
    • Yar 2.0.2
    • Phpalcon 3.3.1
    • Xhprof_tideways 4.1.5
    • Msgpack
    • Protobuf
    • Yaconf
    • Mongodb
    • Seaslog
    • Gearman 1.1.18

Related directories:

    • PHP root directory:/usr/local/php/
    • PHP executable directory:/usr/local/php/bin/,/usr/local/php/sbin/
    • PHP Configuration directory:/usr/local/php/etc/
    • Nginx root directory:/usr/local/nginx/
    • Nginx Executable directory:/usr/local/nginx/sbin/
    • Nginx Configuration directory:/usr/local/nginx/conf/

Download the packaged image file ysphp.tar.gz (239M, Password: nged), and then:

tar xvf ysphp.tar.gzdocker load --input ysphp.tar

Or:

docker pull hub.c.163.com/jiancaigege/php71-fpm-centos68-phalcon-withext:latest
Start container

Make sure that there is a local /work/ directory (Windows uses the VirtualBox shared folder).

1. Manually start the container

    • Use the default configuration in the container:

      docker run -d --restart=always --name ysphp  -p 80:80  -v /work/:/work/   php71-fpm-centos68-phalcon-withext && docker ps -a
    • Custom configuration:
      If you need to modify PHP, nginx configuration file, you need to first git clone -b yphp [email protected]:52fhy/docker-images.git . The GIT repository is a consistent configuration file within the container. You can make custom modifications based on the configuration file. docker-images/yphp yphp Copy the directory below to the /work/ . Then execute:

      docker run -d --restart=always --name ysphp  -p 80:80  -v /work/:/work/   -v "/work/yphp/php/etc/php.ini":/usr/local/php/etc/php.ini   -v "/work/yphp/nginx/conf/nginx.conf":/usr/local/nginx/conf/nginx.conf   -v "/work/yphp/nginx/conf/vhost/":/usr/local/nginx/conf/vhost/   -v "/work/yphp/nginx/logs/":/usr/local/nginx/logs/   php71-fpm-centos68-phalcon-withext && docker ps -a

The container exposes 80 ports externally.

If the current environment is Mac or Linux, direct access to http://127.0.0.1:80/can access the HTTP service provided by port 80 in the container.
If the current environment is Docker ToolBox, then you need to get the IP address of your machine and then access: http://machine-ip:80/.

2. Start the container with the yphp.sh script

Perform:

sh yphp.sh init

To start the container service.

Description of the yphp script: https://github.com/52fhy/docker-images/tree/yphp

Resources

1, Docker learning notes-Fei Hong Ying-Blog Park
Http://www.cnblogs.com/52fhy/p/5638571.html
2, Docker-images/php71-fpm-centos68-phalcon-withext at Master 52fhy/docker-images
Https://github.com/52fhy/docker-images/tree/master/php71-fpm-centos68-phalcon-withext

PHP7 development environment based on Docker deployment

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.