Software used in the article:

  • Mac: 11.4(macOS Big Sur), processor: Intel Core
  • Docker: 3.3.3

The target

  • Support for PHP 5.6.x environment
  • Support for PHP 7.2.x environment

download

Docker software download installation, do not do too much explanation, step by step installation can be.

Download address: www.docker.com/products/do…

The proxy Settings

"registry-mirrors" : [
    "http://registry.docker-cn.com",
    "http://hub-mirror.c.163.com"
  ],
Copy the code

Configure the environment

PHP 7.2.x occupies local port 8081

  1. Start the docker.
  2. Download the zip package: php7-2-x.zip and unzip it;
  3. Go to php7-2-x and run it directlydocker-compose upCan;
  4. Browser type: http://127.0.0.1:8081/;

PHP 5.6.x, occupying local port 8082

  1. Start the docker.
  2. Download the zip package: php5-6-x.zip and unzip it;
  3. Go to php5-6-x and run it directlydocker-compose upCan;
  4. Browser type: http://127.0.0.1:8082/;

Port mapping

Local.php72.com – > 127.0.0.1:8081

Because port mapping cannot be performed in the /etc/hosts file, you need to use other tools.

The tool I used was the Chrome plugin: Simple Proxy.

Download method:

  • Chrome App Store download, searchSimple Proxy.
  • Download the local extension from chrome-simply-proxy

Take a look at the installation interface:

After the configuration is successful, access local.php72.com/

Local.php56.com – > 127.0.0.1:8082

Same as above.

note

Docker-compose related commands

  • Docker-compose up construct container parameter [-d] is background operation
  • Docker-compose start enables the container
  • Docker-compose stop stops the container
  • Docker-compose restart restarts the container
  • Docker-compose Down deletes the container
  • Docker-compose ps views the current container state

Php7-2-x directory introduction

. ├ ─ ─ docker - compose. Yml ├ ─ ─log│ └ ─ ─ nginx │ └ ─ ─ _access local.php72.com. Log ├ ─ ─ phpdocker │ ├ ─ ─ the README. HTML │ ├ ─ ─ the README. Md │ ├ ─ ─ nginx │ │ └ ─ ─ ├─ ├─ 07.02.phpCopy the code

1, docker-comemess. yml, container-orchestrated configuration file, no need to change the file.

Version: "3.1" services: webServer: image: nginx:alpine Container_name: php7-2-x-webServer working_dir: /application volumes: - .:/application - ./phpdocker/nginx:/etc/nginx/conf.d ports: - "8081:80" php-fpm: build: phpdocker/php-fpm container_name: php7-2-x-php-fpm working_dir: /application volumes: -. : / application - / - FPM/PHP - phpdocker/PHP ini - overrides. Ini: / etc/PHP / 7.2 / FPM/conf. D / 99 - overrides. IniCopy the code

Log /nginx is the log directory, including *_access.log and _php_errors.log, and is the configured virtual domain name.

3, phpdocker/nginx is the virtual domain name configuration directory, where default.conf is configured as the virtual domain name local.php72.com, but the other directories and files need not be adjusted.

server {
    listen 80;

    server_name local.php72.com;

    client_max_body_size 108M;

    access_log /application/log/nginx/${server_name}_access.log;


    root /application/web/phpinfo;
    index index.php;

    # try to serve file directly, fallback to index.php
    location / {
        try_files $uri /index.php$is_args$args;
    }

    if (!-e $request_filename) {
        rewrite ^.*$ /index.php last;
    }

    location ~ \.php$ {
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "error_log=/application/log/nginx/${server_name}_php_errors.log";
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        include fastcgi_params;
    }
    
}

Copy the code

4. Web is the code repository directory, where phpInfo is the code directory pointed to by the domain name local.php72.com.

To add a virtual domain name (local.abc.com) configuration, perform the following steps:

  1. Put the code folder ABC in the Web directory;
  2. Add a new file local.abc.com.conf to point the code directory to the ABC directory in the configuration file;
  3. Docker-compose restart docker-compose restart

Php5-6-x directory introduction

Same as above.

How is the ZIP file generated?

You may wonder how the ZIP file is generated, and what if I want to build another version of the environment?

These files are generated online at phpdocker.io/generator

X, 7.1.x, 7.2.x, 7.3.x, and 7.4.x are supported.

It also supports MySQL, MariaDB, Elasticsearch, etc.

After selecting as needed, click Generate Project Archive to Generate the compressed package.

Php5-6-x. zip and php7-2-X. zip above are generated this way, with only minor tweaks, such as configuring the log directory, web directory, etc.

More functions, everyone to explore.

To download the zip file used in the article, please reply to phpDocker at the “new Light notes” public account.

Recommended reading

  • SSO SSO