In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
First of all, you need to have the required tar packages in the environment, and you can use [docker pull] () to download these images.
Now we are using the downloaded image, so we need to import it.
[root@docker01] # docker load-I nginx.tar & & docker load-I wordpress.tar & & docker load-I mysql-5.7.tar & & docker load-I php.7.2-fpm.tar// Import nginx,wordpress,mysql,php Image
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.
Deploy LNMP
[172.16.10.0amp 24] ()
[Nginx:172.16.10.10] ()
[Mysql:172.16.10.20] ()
[Php: 172.16.10.30] ()
Home directory for website access: / wwwroot
Configuration file for Nginx: / docker
/ etc/nginx/conf.d # nginx configuration file
[root@docker01 ~] # docker run-itd-- name test nginx:latest / / start a nginx first, which is used to copy configuration files and access the home directory [root@docker01 ~] # mkdir-p / wwwroot / docker// to create a mount directory [root@docker01 ~] # docker cp test:/etc/nginx / docker/// copy configuration files to the mount directory [root@docker01 ~] # ls / docker/nginx
/ usr/share/nginx/html # nginx home directory
[root@docker01 ~] # docker cp test:/usr/share/nginx/html / wwwroot/// copy access directory to mount directory [root@docker01 ~] # ls / wwwroot/html1) create a custom network [root@docker01 ~] # docker network create-d bridge-- subnet 172.16.10.0 lnmp2 24-- gateway 172.16.10.1 lnmp2) run the nginx container [root@docker01 ~] # netstat-anpt | grep 80 / View port 80 is Not occupied [root@docker01] # docker run-itd-- name nginx-v / docker/nginx:/etc/nginx-v / wwwroot/html:/usr/share/nginx/html-p 80:80-- network lnmp-- ip 172.16.10.10 nginx// running a nginx service And specify ip, map port, mount directory [root@docker01 ~] # docker ps// to check whether the container exists.
[root@docker01 ~] # cd / wwwroot/html [root@docker01 wwwroot] # vim index.htmlhello lnmpins / create a test page [root@docker01 wwwroot] # curl 127.0.0.1hello lnmpins / test visits 3) run mysql Container [root@docker01 html] # docker run-- name mysql-e MYSQL_ROOT_PASSWORD=123.com-d-p 3306 MYSQL_ROOT_PASSWORD=123.com 3306-- network lnmp-- ip 172.16.10.20 mysql:5.7// runs a nginx service and specifies ip, mapping port
-e: set environment variables
[root@docker02 ~] # docker ps
Install mysql and set the password
[root@docker01 html] # yum-y install mysql// install MySQL [root @ docker01 ~] # mysql-u root-p123.com-h 127.0.0.1-P 3306
Randomly create a new library for verification:
MySQL [(none)] > create database name
Then check to see if there is a library you just created:
MySQL [(none)] > show databases
4) run the php container and create the php page [root@docker01 html] # docker run-itd-- name phpfpm-p 9000 docker run 9000-v / wwwroot/html:/usr/share/nginx/html-- network lnmp-- ip 172.16.10.30 php:7.2-fpm [root@docker01 ~] # cd / wwwroot/html [root@docker01 wwwroot] # vim test.php// add php test interface [root@docker02 ~] # docker ps
5) modify the nginx configuration file, and connect nginx and php to [root@docker01 html] # cd / docker/nginx/conf.d/ [root@docker01 conf.d] # vim default.conf location / {root / usr/share/nginx/html; index index.html index.htm index.php; # 10 to add index.php}
Location ~\ .php$ {root / usr/share/nginx/html; fastcgi_pass 172.16.10.30 root 9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;}
Restart nginx after setting up
[root@docker01 conf.d] # docker restart nginx// restart nginx [root@docker01 conf.d] # docker ps
Browser test access to nginx and php
The description is the connection between nginx and php, no problem, and then the connection between php and MySQL. Here we use a phpmyadmin database management tool
6) modify nginx configuration file, php and mysql connection [root@docker01 html] # cd / wwwroot/html
Upload phpMyAdmin package. If not, please download it at https://github.com/phpmyadmin/phpmyadmin/releases.
[root@docker01 html] # unzip phpMyAdmin-4.9.1-all-languages.zip / / extract phpmyadmin package [root@docker01 html] # mv phpMyAdmin-4.9.1-all-languages phpmyadmin// change the name of the file you just extracted [root@docker01 html] # cd / docker/nginx/conf.d/ [root@docker01 conf.d] # vim default.conf / / modify the nginx configuration file location / phpmyadmin {root / usr/share/nginx/html Index index.html index.htm index.php;}
Location ~ / phpmyadmin/ (? (. *)\. (php | php5)? $) {root / usr/share/nginx/html; fastcgi_pass 172.16.10.30 root 9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;}
[root@docker01 conf.d] # docker restart nginx [root@docker01 conf.d] # docker ps
Browsers access http://192.168.1.11/phpmyadmin/index.php
The red box is a normal phenomenon, don't panic, and then solve it.
We need to make changes to the php image and add php and MySQL connection modules
Write a Dockerfile
[root@docker01 conf.d] # cd [root@docker01 ~] # vim DockerfileFROM php:7.2-fpmRUN apt-get update & & apt-get install-y\ libfreetype6-dev\ libjpeg62-turbo-dev\ libpng-dev\ & & docker-php-ext-install-j$ (nproc) iconv\ & & docker-php-ext-configure gd-- with-freetype-dir=/usr/include/-- with-jpeg-dir=/usr/include/ \ & & docker-php-ext-install-j$ (nproc) gd\ & & docker-php-ext-install mysqli pdo pdo_mysql
Create php image based on dockerfile
[root@docker01 ~] # docker build-t phpmysql. / / create an image based on Dockerfiler
Delete the previous php container
[root@docker01 ~] # docker stop phpfpm [root@docker01 ~] # docker rm phpfpm / / close and delete the php container
Run the container with the new php image
[root@docker01] # docker run-itd-- name phpfpm-p 9000 itd 9000-v / wwwroot/html:/usr/share/nginx/html-- network lnmp-- ip 172.16.10.30 phpmysql// re-run with the newly made php image
/ / modify the configuration file of phpmyadmin, specify the IP of the connected database, and then restart the php container
[root@docker01 html] # cd / wwwroot/html/phpmyadmin/ [root@docker01 phpmyadmin] # cp config.sample.inc.php config.inc.php [root@docker01 phpmyadmin] # vim config.inc.php$cfg ['Servers'] [$] [' auth_type'] = 'cookie';/* Server parameters * / $cfg [' Servers'] [$] ['host'] =' 172.16.10.20]; # 31 write the IP address of the mysql database $cfg ['Servers'] [$I] [' compress'] = false $cfg ['Servers'] [$I] [' AllowNoPassword'] = false
[root@docker01 phpmyadmin] # docker restart phpfpm / / restart the phpfpm container
Browser test access to http://192.168.1.11/phpmyadmin/index.php
User name: root password: 123.com
After logging in successfully, you can see the database created by mysql before.
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.