Table of Contents
Support PHP 5.6.x Environment
Docker software download and installation, without too much explanation, just install it step by step.
Home Backend Development PHP Tutorial Example introduction: Use Docker to quickly build a multi-version PHP development environment

Example introduction: Use Docker to quickly build a multi-version PHP development environment

Dec 28, 2022 pm 06:03 PM
php

This article brings you relevant knowledge about PHP, which mainly introduces the relevant content on how to use docker to quickly build a multi-version PHP development environment. Let’s take a look at it together and hope it will be helpful to everyone. helpful.

Example introduction: Use Docker to quickly build a multi-version PHP development environment

## Recommended study: "

PHP Video Tutorial"

Software used in the article:

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

  • Docker: 3.3.3

Example introduction: Use Docker to quickly build a multi-version PHP development environment## Target

Support PHP 5.6.x Environment

Supports PHP 7.2.x Environment

Download

Docker software download and installation, without too much explanation, just install it step by step.

Download address: Docker official website https://www.docker.com/products/docker-desktop

Agent settings

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

Example introduction: Use Docker to quickly build a multi-version PHP development environment Configure environment

PHP 7.2.x, occupy local port 8081

    Start docker;
  • Download the compressed package: php7-2-x.zip and decompress it;
  • Enter the php7-2-x directory and run docker-compose up directly;
  • Browser input: http://127.0.0.1:8081/;

Example introduction: Use Docker to quickly build a multi-version PHP development environment##PHP 5.6.x , occupying local port 8082

Start docker;
  • Download the compressed package: php5-6-x.zip and decompress it;
  • Enter the php5-6-x directory and run docker-compose up directly;
  • Browser input: http:// 127.0.0.1:8082/;

Port mappingExample introduction: Use Docker to quickly build a multi-version PHP development environment

local.php72.com -> 127.0.0.1:8081

Because port mapping cannot be done in the /etc/hosts file, other tools are needed.

The tool I used is the Chrome browser plug-in: Simple Proxy.

Download method:

Download from the Chrome App Store and search for Simple Proxy.
  • Load the local extension, download address: chrome-simply-proxy[2]
  • Look at the installed interface:

After successful configuration, visit http://local.php72.com/Example introduction: Use Docker to quickly build a multi-version PHP development environment

##local.php56.com - > 127.0.0.1:8082Example introduction: Use Docker to quickly build a multi-version PHP development environment

Same as above. Remarks

docker-compose related commands

docker-compose up Build container parameters [-d] for background operation

  • docker-compose start Enable container

  • docker-compose stop Stop container

  • docker- compose restart Restart the container

  • docker-compose down Delete the container

  • ##docker-compose ps View the current container status

  • php7-2-x Directory Introduction

  • ├── docker-compose.yml
    ├── log
    │   └── nginx
    │       └── local.php72.com_access.log
    ├── phpdocker
    │   ├── README.html
    │   ├── README.md
    │   ├── nginx
    │   │   └── default.conf
    │   └── php-fpm
    │       ├── Dockerfile
    │       └── php-ini-overrides.ini
    └── web
        └── phpinfo
            └── index.php
    Copy after login
1. docker-compose.yml, the configuration file for container orchestration, the file does not need to be changed.

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
        - ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
Copy after login
2. log/nginx is the log directory, including xxx_access.log and xxx_php_errors.log, and xxx is the configured virtual domain name.

3. phpdocker/nginx configures the directory for the virtual domain name. The virtual domain name configured in default.conf is local.php72.com. No need to explain too much. Everyone can understand it at a glance. Other directories and files do not need to 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 after login
4. web is the code warehouse directory, where phpinfo is the code directory pointed to by the domain name local.php72.com.

If you want to add a new virtual domain name (local.abc.com) configuration, you only need 3 steps:

Place the code folder abc in the web directory ;

  • Add the file local.abc.com.conf and point the code directory to the abc directory in the configuration file;

  • Restart the container docker-compose restart;

  • php5-6-x directory introduction

    Same as above.

How to generate zip file?

You may have questions, how is the zip file generated? What if I want to build another version of the environment?

These files are generated online, URL: https://phpdocker.io/generator[3]

Supported PHP versions are: 5.6. x, 7.0.x, 7.1.x, 7.2.x, 7.3.x, 7.4.x, etc.

It also supports MySQL, MariaDB, Elasticsearch, etc. Example introduction: Use Docker to quickly build a multi-version PHP development environment

After selecting as needed, click Generate project archive to generate the compressed package.

The above php5-6-x.zip and php7-2-x.zip are generated in this way. They are just fine-tuned, such as configuring the log directory, web directory, etc.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Example introduction: Use Docker to quickly build a multi-version PHP development environment. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles