PHP Local Development Environment Docker installation

Source: Internet
Author: User
Tags mysql host php cli phpinfo docker stop container docker ps

This article mainly introduces about the PHP Local development environment Docker installation, has a certain reference value, now share to everyone, the need for friends can refer to

Docker PHP Local Development environment

Lu Xun: Don't want to hit the product programmer, not good sales

Objective

Many people in the configuration of Docker, because do not understand the contents of his directory structure, configuration problems, which will lead to many do not understand the place.

But, lad, you read this article, you are right. I will quickly take you into the Docker pit in a "dapper" language. Maybe in the article, write about what is wrong with your values, please use your small fists to smash your ctrl+f4. I am a person who can not afford to scold, if you scold me (I will give you a chance to scold me?) To kill first) (manual funny).

It is strongly recommended that csdn add emoji expression.

MySQL installation body

MySQL installation is relatively much simpler

[Root@test app]#  Docker pull Mysql:5.7[root@test app]#   Docker run--name mysql_server-p 3308:3308-e mysql\_root \_password=123456-d mysql:5.7 Command Explanation #-E built-in environment variable here is the password for the root account is not set.

However, we install the need to install MySQL before installing PHP because between the containers, need –link to make two containers have interactive communication. Otherwise. Hey, you know that. PHP is not connected to MySQL. The order is explained, and the following are all:

PHP Installation Body

1. Preparatory work

Because the main computer is the Ubuntu system, so the text of some of the commands, unified for Ubuntu in addition to installation, it seems that there is nothing incompatible with other systems.
Docker installation,
Windows installation
Linux
Mac

1. Docker Environment
2. PHP:7.2.4-FPM image (the environment for your project) official image
3, the official MYSQL image (see your own mood is not installed)

(funny) Some readers may ask why not nginx|apache, because simplifying your operation. Get you started faster, and get you to write code faster.

When you download Docker, turn on Docker


When Docker is turned on, Docker version prints the server information and does not print if it is not turned on.
Please open Docker

2. Start

1. [Root@test app]# Docker pull php:7.2.5-fpm #docker pulled image, pulling an image from Docker image 2, [Root@test app]# Docker image             s #docker all current mirror names imagesrepository TAG image ID CREATED sizedocker.io/php 7.2.5-fpm e6970efc6d34 3 days ago 367 MB3, [Root@test app]# Dock Er run-d-P 8080:8080--link mysql_server:mysql_server-v ~/app:/app-w/app php:7.2.5-fpm php-s 0.0.0.0:8080-t/app command EXPLANATION #-D Background default boot #-p map port 8080 map to native 8080 usage local port: Container Port #-V hangs in directory ~/app mount to container inside/app Directory #-W working directory/app directory equivalent to CD (here we can not) #-- Link Connection container container name: Internally used name # PHP:7.2.5-FPM Mirror name # php-s 0.0.0.0:8080-t/app php comes with CLI Server with this can exempt Nginx|apache installation, specify Port as 8080.             4. [Root@test app]# Docker PS #查看正在运行的容器CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS names9354f9338e29 php:7.2.5-fpm "Docker-php-entryp   ..." 4 minutes AGo up 4 minutes 0.0.0.0:8080->8080/tcp, 9000/tcp Naughty_fermi Here we can see, NAMES is the container name, when we do not specify, Docker will automatically Create a container name. PORTS Port, 0.0.0.0:8080->8080/tcp native 8080 map to container 8080

3. Test:

We create a new index.php in the app directory

<?php phpinfo ();

Open 127.0.0.1:8080 to see our familiar phpinfo

4. Install the extension

If you do not need to install the extension, please watch!!!

Here we explain 2 ways to install and expand

1. Enter the container to install the extension

First, view the Docker container name

[Root@test app]# Docker pscontainer ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                              Names9354f9338e29        php:7.2.5-fpm       "Docker-php-entryp ..."   minutes ago up to      minutes       0.0.0.0:8080->8080/tcp, 9000/tcp   naughty_fermi

We saw the Docker name Naughty_fermi here.
Second, enter the container

1. Enter the container [root@test app]# Docker exec-i-T naughty_fermi/bin/bashroot@9354f9338e29:/app# #这样子, and see that we have entered the running container command explanation # Docker exec enters the container being used #-I: Even without attaching also keep stdin open general and-T Cooperative use #-T: Assign a pseudo terminal general and-I cooperation using #/bin/bash to open the interactive terminal Terminal 2. [Root@test app]# docker-press TAB twice to see Docker-php-entrypoint docker-php-ext-configure docker-php-ext-enable docker-p Hp-ext-install Docker-php-source #docker Some scripts have been written for us based on some common libraries docker-php GitHub address [GitHub] (3. Installation Extension Example: Sockets [Root@t EST app]# docker-php-ext-install sockets quietly waiting for him to compile the installation [Root@test app]# Php-m # will be able to see the sockets library. 4. Exit the container to exit the container is a bit special, need ctrl+p and CRTL + Q in order to continue to suspend in the background root@9354f9338e29:/app# [Root@test app]# [Root@test app]# 4. We need to restart our CLI Server [root@test app]# ps-ef |        grep php root 11840 11808 0 17:04? 00:00:00 php-s 0.0.0.0:8080-t/approot 14923 9900 0 17:54 pts/1 00:00:00 grep--color=auto php find our PHP cli-ser Ver pid for 11840 Docker inside these processes, is inside the machine can see. Here's an explanation [explanation] (http://dockone.io/question/529) We're back on our local machine. [Root@test app]# kiLl-9 11840 # Kill Our process because we've killed our process, so PHP will automatically shut down we'll start this container from the new one, such as the above can see our names for Naughty_fermi[root@test app]# Docker start Naughty_fermi This opens the extension.

So our extension is ready to be installed.

Note: There are some extensions that require some dependency, and in some cases we may need to rely on some of them before we install them. PHP code inside the connection, MySQL host can not use 127.0.0.1 or localhost. Replace the link with the name of the Mysql_server MySQL container.

2. External installation and expansion

1. [Root@test app]#  Docker exec-d Naughty_fermi Docker-php-ext-install opcache# Here we use Opcache as an example Docker exec doesn't have to explain. There are #-D background Default # container names followed by commands running inside the container 2. Repeat the 4 operation on the internal installation is similar to Cli-server and PHP-FPM, each new extension requires a reboot.

Once we've configured it for the first time, we'll need the Docker start container name to open it, and here's a few commands to explain.

1. Docker start container name Open container
2. Docker stop container name stops container
3. Docker kill container name kills container

In Docker run you can specify--name the container name to give the container a name such as

Docker run-d-P 8080:8080--name php_server-v ~/app:/app-w/app php:7.2.5-fpm php-s 0.0.0.0:8080-t/app
In this way, our container name can be defined by itself.

Other, what's the problem, send me an email. My e-mail is

Uyy2244@gmail.com

Remember to explain the problem in detail, please. otherwise ignore.

Remember: This article applies only to the local development environment.

The above is the entire content of this article, more relevant content please pay attention to topic.alibabacloud.com.

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.