文章目录
-
- 一、创建存储路径及网络
- 二、运行nginx容器
- 三、运行mysql容器
- 四、运行php容器
- 五、nginx和php连接
- 六、php和mysql的连接
- 七、部署web应用
一、创建存储路径及网络
[root@localhost ~]
[root@localhost ~]
二、运行nginx容器
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
123456

三、运行mysql容器
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@docker01 ~]
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
MySQL [(none)]> exit
Bye
四、运行php容器
[root@localhost ~]
[root@localhost ~]
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 172.16.10.30:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[root@localhost ~]
<?php
phpinfo();
?>
[root@localhost ~]
nginx

五、nginx和php连接
[root@localhost ~]
[root@localhost html]
[root@localhost html]
[root@localhost html]
[root@localhost html]
[root@localhost conf.d]
location /phpmyadmin {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
location ~ /phpmyadmin/(?<after_ali>(.*)\.(php|php5)?$) {
root /usr/share/nginx/html;
fastcgi_pass 172.16.10.30:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[root@localhost ~]
nginx

六、php和mysql的连接
[root@localhost ~]
[root@localhost lnmp]
FROM php:7.4-fpm
RUN 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=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install mysqli pdo pdo_mysql
[root@localhost lnmp]
[root@localhost ~]
phpfpm
[root@localhost ~]
phpfpm
[root@localhost ~]
[root@localhost ~]
[root@localhost phpmyadmin]
[root@localhost phpmyadmin]
$cfg['Servers'][$i]['host'] = '172.16.10.20';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
[root@localhost ~]
nginx


七、部署web应用
[root@localhost ~]
[root@localhost html]
[root@localhost html]
[root@localhost ~]
MySQL [(none)]> create database blog;
Query OK, 1 row affected (0.01 sec)
MySQL [(none)]> grant all on blog.* to lisi@'172.16.10.%' identified by '123.com';
Query OK, 0 rows affected, 1 warning (0.00 sec)
MySQL [(none)]> exit
Bye
[root@localhost ~]
nginx


