In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces how to deploy the LNMP environment in Docker, the content is very detailed, interested friends can refer to, hope to be helpful to you.
The whole process:
The client http requests the server port 80, which is mapped to port 80 of the Nginx container and entered into Nginx processing.
Nginx analysis request, if it is a static resource, read the content directly from the server; if it is a PHP script, call the server through the PHP container to get the script, and then FastCGI process it.
FastCGI parses the PHP script and accesses the MySQL container to read and write data if necessary.
Concrete steps
Dockerfile:
MySQL Mirror
Inherited from the official MySQL5.7 image, relatively independent decoupling module, no other additional processing, see mysql/Dockerfile.
PHP Mirror
Inherited from the official centos7 image, PHP source code is compiled and installed on demand to facilitate subsequent extension management or configuration. Modify php.in to listen on all 9000 ports via sed (here is the key! Because PHP scripts are supported for Nignx container access, PHP containers are not localhost for Nginx containers. For more information, please see php7/Dockerfile.
Nginx Mirror
Inherited from the official centos7 image, Nginx source code is compiled and installed on demand to facilitate subsequent changes or configuration. Modify nginx.conf through sed to add support for PHP scripts. For more information, please see nginx/Dockerfile.
Build an image:
Docker build-- tag addcn/mysql-f mysql/Dockerfile. Docker build-- tag addcn/php7-f php7/Dockerfile. Docker build-- tag addcn/nginx-f nginx/Dockerfile.
Start the container:
The whole process shows the relationship among Nginx, PHP and MySQL:
Nginx container-> PHP container, PHP container-> MySQL container. That is to say, there is an association between containers, and the data communication between two containers is solved by the container startup command docker run plus the parameter-link.
Docker run-- name mysql-p 3306 MYSQL_ROOT_PASSWORD=123456 3306-v / root/bo/data/mysql:/var/lib/mysql-e MYSQL_ROOT_PASSWORD=123456-it addcn/mysqldocker run-- name php7-p 9000Pho 9000-v / var/www/html:/usr/local/nginx/html-- link mysql:mysql-it addcn/php7docker run-- name nginx-p 80:80-v / var/www/html:/usr/local/nginx/html-- link php7:php7-it addcn/nginx
Test PHP & MySQL:
Vi / var/www/html/test.php
Client browsing:
Http://192.168.8.36/test.php
! [Docker runs PHP and outputs MySQL table] [1]
[1]: https://cache.yisu.com/upload/information/20210524/347/781130.png
Quan A
How does Nginx support PHP scripts?
When the Nginx container starts, use the-link php7:php7 parameter to share the network of the PHP container, configure the nginx.conf file (see nginx/Dockerfile), and when processing the PHP script, transfer it to the PHP container for parsing:
Location ~\\ .php ${root html; fastcgi_pass php7:9000; # here is the key! Where php7 is the name of the PHP container, see launch PHP container docker run-- name specified value fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME / usr/local/nginx/html$fastcgi_script_name; # key! / usr/local/nginx/html is the web directory include fastcgi_params;}
How does PHP read MySQL data?
When the PHP container starts, it shares the network with the MySQL container through the-- link mysql:mysql parameter, similar to the fact that the two are on the same machine, so the PHP code uses $conn = new PDO ('mysql:host=mysql;port=3306;dbname=mysql;charset=utf8',' root', '123456'); you can connect to the MySQL (where the mysql of host=mysql is the name of the MySQL container, see the value specified to launch the MySQL container docker run-- name).
On how to deploy the LNMP environment in Docker to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.