win10 docker-toolsbox tutorial on building a php development environment

win10 docker-toolsbox tutorial on building a php development environment

Download image

docker pull mysql:5.7 
docker pull php:7.2-fpm
docker pull nginx
docker pull redis:3.2

Set up shared files

Create a directory on the host

E:\wnmp\mysql57\conf
E:\wnmp\mysql57\log
E:\wnmp\php72\conf
E:\wnmp\php72\conf
E:\wnmp\nginx\conf
E:\wnmp\nginx\conf
E:\wnmp\www

vmware file sharing settings

As shown

After the setup is complete, execute docker-machine restart default in Docker Quickstart Termina

Install MySQL

docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name mysql57 mysql:5.7

Copy the configuration file

PS C:\Windows\system32>docker cp mysql57:/var/log/mysql E:\wnmp\mysql57\log
PS C:\Windows\system32>docker cp mysql57:/etc/mysql E:\wnmp\mysql57\conf

Reinstall mysql and specify the configuration file

PS C:\WINDOWS\system32> docker stop mysql57
mysql57
PS C:\WINDOWS\system32>docker rm mysql57
mysql57
PS C:\WINDOWS\system32> docker run -d -v /wnmp/mysql57/log:/var/log/mysql/ -v /wnmp/mysql57/conf:/etc/mysql/ -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name mysql57 mysql:5.7

Initialize the database

docker exec -ti mysql57 /bin/bash
mysql_secure_installation 
# View Mysql status root@d7bd0712bcf8:/# mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Install PHP

PS C:\WINDOWS\system32> docker run -d -v /wnmp/www:/var/www/html -p 9000:9000 --link mysql57:mysql --name php72 php:7.2-fpm

Copy the configuration file

PS C:\Windows\system32>docker cp php72:/usr/local/etc E:\wnmp\php72\conf
PS C:\Windows\system32>docker cp php72:/usr/local/var/log E:\wnmp\php72\log
PS C:\Windows\system32> docker cp php72:/var/www/html E:\wnmp\www

Reinstall PHP and specify the configuration file

PS C:\WINDOWS\system32> docker stop php72
php72
PS C:\WINDOWS\system32>docker rm php72
php72
docker run -d -v /wnmp/php72/conf/etc:/usr/local/etc -v /wnmp/php72/log:/usr/local/var/log -v /wnmp/www:/var/www/html -p 9000:9000 --link mysql57:mysql --name php72 php:7.2-fpm
# Check the PHP version PS C:\Windows\system32> docker exec -ti php72 /bin/bash
root@742150f14d8a:/var/www/html# php -v
PHP 7.2.23 (cli) (built: Oct 5 2019 00:31:47) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
Ngixn

Install

PS C:\WINDOWS\system32> docker run -d -p 80:80 --link php72:phpfpm --name nginx nginx:latest

Copy the configuration file

PS C:\Windows\system32>docker cp nginx:/etc/nginx/ E:\wnmp\nginx\conf
PS C:\Windows\system32>docker cp nginx:/var/log/nginx/ E:\wnmp\nginx\log

Reinstall and specify the configuration file

PS C:\WINDOWS\system32> docker stop nginx
nginx
PS C:\WINDOWS\system32>docker rm nginx
nginx
PS C:\WINDOWS\system32> docker run -d -p 80:80 -v /wnmp/www:/var/www/html -v /wnmp/nginx/conf/nginx:/etc/nginx/ -v /wnmp/nginx/log:/var/log/nginx/ --link php72:phpfpm --name nginx nginx
#Browser access http://192.168.99.100/ Verify successful Redis
docker run -p 6379:6379 -d redis:3.2 redis-server

PHP extension installation

redis
PS C:\Windows\system32> docker exec -ti php72 /bin/bash
root@742150f14d8a:/var/www/html# pecl install -o -f redis
#Installation completed, add Ini configuration. At this time, the redis configuration under docker is in E:\wnmp\php72\conf\etc\php\conf.d\docker-php-ext-sodium.ini
# Restart php

Configure the test domain name

#Create a new test.conf in the E:\wnmp\nginx\conf\nginx\conf.d directory
#Create a new test directory in the E:\wnmp\www directory. Create index.php in the directory and output phpinfo;
server {
  listen 80;
  server_name test.com;
  #charset koi8-r;
  access_log /var/log/nginx/host.access.log main;
  location / {
    root /var/www/html/test;
    index index.php index.html index.htm;
  }
  #error_page 404 /404.html;
  # redirect server error pages to the static page /50x.html
  #
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
    root /usr/share/nginx/html;
  }
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  #
  #location ~ \.php$ {
  # proxy_pass http://127.0.0.1;
  #}
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  location ~ \.php$ {
     root /var/www/html/test;
    fastcgi_pass 192.168.99.100:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  location ~ /\.ht {
    deny all;
  }
}
#Nginx reloads configuration or restarts.
#Local host resolves the domain name test.com and access shows that phpinfo is normal

The above is all installation configuration and testing. Of course, in the end we need to add these docker containers to the automatic startup

docker container update --restart=always php72
docker container update --restart=always mysql57
docker container update --restart=always nginx
docker container update --restart=always redis

Summarize

The above is the tutorial on how to use win10 docker-toolsbox to build a php development environment. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Docker's flexible implementation of building a PHP environment
  • How to build php+nginx+swoole+mysql+redis environment with docker
  • Docker builds your own PHP development environment
  • The whole process of using docker to build php7 and nginx operating environment (official image)
  • Docker builds Nginx+PHP+MySQL environment and deploys WordPress practice
  • Tutorial on configuring PHP development environment with Docker
  • Detailed explanation of the solution to the permission problem encountered when creating a PHP development environment with Docker
  • How to use Docker to deploy a PHP development environment
  • A detailed tutorial on building a PHP development environment based on Docker
  • Docker build PHP environment tutorial detailed explanation

<<:  MySQL 8.0.14 installation and configuration method graphic tutorial

>>:  Basic usage and pitfalls of JavaScript array sort() method

Recommend

An IE crash bug

Copy code The code is as follows: <style type=...

JavaScript to achieve simple image switching

This article shares the specific code for JavaScr...

Analysis of the implementation of MySQL statement locking

Abstract: Analysis of two MySQL SQL statement loc...

How to redirect nginx directory path

If you want the path following the domain name to...

Vue's Render function

Table of contents 1. Nodes, trees, and virtual DO...

Install MySQL in Ubuntu 18.04 (Graphical Tutorial)

Tip: The following operations are all performed u...

Html long text automatically cuts off when it exceeds the tag width

When we display long text, we often need to interc...

CSS code to control the background color of the web page

I think everyone often worries about finding pict...

Teach you how to deploy Vue project with Docker

1.Write in front: As a lightweight virtualization...

Implementation of MySQL5.7 mysqldump backup and recovery

MySQL backup Cold backup:停止服務進行備份,即停止數據庫的寫入Hot ba...

Detailed explanation of common methods of Vue development

Table of contents $nextTick() $forceUpdate() $set...

Why the table file size remains unchanged after deleting data in MySQL

For databases that have been running for a long t...

jQuery plugin to implement stacked menu

A jQuery plugin every day - stacked menu, for you...

How to deploy nextcloud network disk using docker

NextCloud You can share any files or folders on y...