


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.
PHP Video Tutorial"
Software used in the article:- Mac: 11.4 (macOS Big Sur), processor: Intel Core.
- Docker: 3.3.3
## 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" ],
Configure environment
- 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/;
##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 mapping
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/
##local.php56.com - > 127.0.0.1:8082
Same as above. Remarks
docker-compose related commandsdocker-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.php1. 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.ini2. 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; } }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 introductionSame 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.
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!

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft