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.
## Recommended study: "PHP Video Tutorial"
Software used in the article:## Target
Supports PHP 7.2.x Environment
Download
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
PHP 7.2.x, occupy local port 8081##PHP 5.6.x , occupying local port 8082
Start docker;
Port mapping
local.php72.com -> 127.0.0.1:8081Because 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.
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
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
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
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; } }
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!