网站开发的合同编写,优化方案2022,wordpress functions.php 在哪,石河子规划建设局网站文章目录 前期准备#xff1a;一、部署mysql1.1 获取 Mysql 5.7.22 镜像1.2 启动mysql容器 二、部署php2.1 获取php 7.2镜像2.2 启动php 容器2.3 php的扩展安装 三、部署nginx3.1 获取nginx:1.14镜像3.2 启动nginx容器3.3 编写nginx虚拟主机配置文件#xff0c;使其支持php3.… 文章目录 前期准备一、部署mysql1.1 获取 Mysql 5.7.22 镜像1.2 启动mysql容器 二、部署php2.1 获取php 7.2镜像2.2 启动php 容器2.3 php的扩展安装 三、部署nginx3.1 获取nginx:1.14镜像3.2 启动nginx容器3.3 编写nginx虚拟主机配置文件使其支持php3.4 php测试静态页编写 四、访问浏览器测试 前期准备
系统环境centos7软件环境docker:18.09.6lnmp环境nginx:1.14 mysql:5.7.22php:7.2
注软件版本可自选
一、部署mysql
1.1 获取 Mysql 5.7.22 镜像
[rootlocalhost ~]# docker pull mysql:5.7.22
5.7.22: Pulling from library/mysql
be8881be8156: Pull complete
......
c3995dabd1d7: Pull complete
2b3c2e6bacee: Pull complete
Digest: sha256:aaba540cdd9313645d892f4f20573e8b42b30e5be71c054b7befed2f7da5f85b
Status: Downloaded newer image for mysql:5.7.221.2 启动mysql容器
创建mysql挂载目录
[rootlocalhost ~]# mkdir -p /opt/app/mysql/mysql编写mysql挂载配置文件
[rootlocalhost ~]# vim /opt/app/mysql/my.cnf[client]
port 3306
socket /tmp/mysql.sock
[mysqld]
datadir/var/lib/mysql
socket/tmp/mysql.sock
port3306
sql_modeNO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
long_query_time 5
slow_query_log 1
slow_query_log_file slow.log
max_connections3000
skip-name-resolve
back_log384
log-binmysql-bin
binlog_formatmixed
expire_logs_days 7
server-id 123编写mysql容器启动脚本
[rootlocalhost ~]# cd /opt/app/mysql/
[rootlocalhost mysql]# ls
my.cnf mysql
[rootlocalhost mysql]# vim mysql-run.sh
#!/bin/bashdocker run -itd --restartunless-stopped -v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone --name mysql -p 13306:3306 -v /opt/app/mysql/mysql:/var/lib/mysql -v /opt/app/mysql/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD123456 mysql:5.7.22为启动脚本赋予执行权限
[rootlocalhost mysql]# chmod x mysql-run.sh [rootlocalhost mysql]# ll mysql-run.sh
-rwxr-xr-x 1 root root 271 8月 6 15:10 mysql-run.sh
启动mysql数据库容器
[rootlocalhost mysql]# pwd
/opt/app/mysql[rootlocalhost mysql]# ./mysql-run.sh
c6d5d69bcede92f6b5ea685af50277924c76ca04b7808bc7dda48292a1b862b9查看mysql容器启动情况
[rootlocalhost php]# docker ps -a --no-trunc --filter name^mysql$
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c6d5d69bcede92f6b5ea685af50277924c76ca04b7808bc7dda48292a1b862b9 mysql:5.7.22 docker-entrypoint.sh mysqld 18 minutes ago Up 18 minutes 0.0.0.0:13306-3306/tcp mysql,php/mysql二、部署php
2.1 获取php 7.2镜像
[rootlocalhost mysql]# docker pull php:7.2-fpm
7.2-fpm: Pulling from library/php
f5d23c7fed46: Pull complete
......
8d5ce70a71c0: Pull complete
Digest: sha256:e52c0cd1487d76decf8523da5b0a65f2cfd47d8bbbfef077476fff90ceae2fa8
Status: Downloaded newer image for php:7.2-fpm
2.2 启动php 容器
创建php存放文件目录
[rootlocalhost ~]# mkdir -p /opt/app/php编写php容器启动脚本
[rootlocalhost ~]# cd /opt/app/php/
[rootlocalhost php]# vim php-run.sh
#!/bin/bashdocker run -d -v /opt/app/nginx/html:/var/www/html -p 9000:9000 --link mysql:mysql --name php php:7.2-fpm为启动脚本赋予执行权限
[rootlocalhost php]# chmod x php-run.sh [rootlocalhost php]# ll php-run.sh
-rwxr-xr-x 1 root root 120 8月 6 15:28 php-run.sh启动php容器
[rootlocalhost php]# ./php-run.sh
7750e24826b74c8fb355cf2abfa27d4eb8a7104672728ad18cd75332e62e2fb9查看php容器启动情况
[rootlocalhost php]# docker ps -a --no-trunc --filter name^php$
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7750e24826b74c8fb355cf2abfa27d4eb8a7104672728ad18cd75332e62e2fb9 php:7.2-fpm docker-php-entrypoint php-fpm 54 seconds ago Up 53 seconds 0.0.0.0:9000-9000/tcp phpphp容器启动参数说明
-d 让容器运行在后台
-p 添加主机到容器的端口映射
-v 添加目录映射这里最好nginx容器的根目录最好写成和php容器中根目录一样。但是不一定非要一样,如果不一样在配置nginx的时候需要注意
-name 容器的名称
-link 容器之间建立起来联系 需要建立联系的容器名:mysql
2.3 php的扩展安装
安装php-redis
进入php容器 docker exec -it php bash
安装php-redis命令 pecl install redis docker-php-ext-enable redis
[rootlocalhost ~]# docker exec -it php bash
root7750e24826b7:/var/www/html# pecl install redis docker-php-ext-enable redis
downloading redis-5.0.2.tgz ...
Starting to download redis-5.0.2.tgz (243,270 bytes)
..................................................done: 243,270 bytes
25 source files, building
running: phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
enable igbinary serializer support? [no] : //no 或者空格都可以
enable lzf compression support? [no] : //no 或者空格都可以
building in /tmp/pear/temp/pear-build-defaultuser9cKHej/redis-5.0.2
running: /tmp/pear/temp/redis/configure
......此处省略
configuration option php_ini is not set to php.ini location
You should add extensionredis.so to php.ini查看安装的php插件 容器内执行php -m
root7750e24826b7:/var/www/html# php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
readline
redis //这就是安装的redis
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib[Zend Modules]
三、部署nginx
3.1 获取nginx:1.14镜像
[rootlocalhost ~]# docker pull nginx:1.14
1.14: Pulling from library/nginx
27833a3ba0a5: Pull complete
0f23e58bd0b7: Pull complete
8ca774778e85: Pull complete
Digest: sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
Status: Downloaded newer image for nginx:1.143.2 启动nginx容器
新建nginx挂载目录
[rootlocalhost ~]# mkdir -p /opt/app/nginx/{conf,html,logs,cert}编写nginx主配置文件
[rootlocalhost ~]# cd /opt/app/nginx/[rootlocalhost nginx]# vim nginx.confworker_processes 4;
user nginx;
#pid /opt/app/nginx/sbin/nginx.pid;
events {worker_connections 409600;
}
http {include mime.types;default_type application/octet-stream;server_tokens off;autoindex on;autoindex_exact_size off;autoindex_localtime on;keepalive_timeout 65;log_format main $remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for;access_log /var/log/nginx/access.log main;error_log /var/log/nginx/error.log error;include /etc/nginx/conf.d/*.conf;
}
编写nginx容器启动脚本
[rootlocalhost nginx]# pwd
/opt/app/nginx[rootlocalhost nginx]# vim nginx-run.sh
#!/bin/bashdocker run -itd --restartunless-stopped -v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone -p 80:80 --name nginx -v /opt/app/nginx/html:/usr/share/nginx/html -v /opt/app/nginx/logs:/var/log/nginx -v /opt/app/nginx/cert:/etc/nginx/cert -v /opt/app/nginx/nginx.conf:/etc/nginx/nginx.conf -v /opt/app/nginx/conf:/etc/nginx/conf.d --link php:phpfpm nginx:1.14
参数解释
-v 添加目录映射这里nginx容器的静态页目录最好和php容器中静态页目录映射的目录一致。但是不一定非要一样,如果不一样在配置nginx的时候需要注意
–link 容器之间建立起来联系,此处nginx需要与php容器建立联系(写法php容器名称:phpfpm)此参数必须写在使用镜像名称之前。
为启动脚本赋予执行权限
[rootlocalhost nginx]# chmod x nginx-run.sh [rootlocalhost nginx]# ll nginx-run.sh
-rwxr-xr-x 1 root root 393 8月 6 16:28 nginx-run.sh启动nginx容器
[rootlocalhost nginx]# ./nginx-run.sh
850e27b026be83886f2deee90d8b36754eb29eeffd1e27e18a6e5724bc29f3f7查看nginx容器启动情况
[rootlocalhost nginx]# docker ps -a --no-trunc --filter namenginx$
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
850e27b026be83886f2deee90d8b36754eb29eeffd1e27e18a6e5724bc29f3f7 nginx:1.14 nginx -g daemon off; 30 seconds ago Up 29 seconds 0.0.0.0:80-80/tcp nginx3.3 编写nginx虚拟主机配置文件使其支持php
[rootlocalhost conf]# pwd
/opt/app/nginx/conf[rootlocalhost conf]# vim nginx-php.conf server {listen 80;server_name 10.20.29.36;location / {root /usr/share/nginx/html;index index.php index.html index.htm;}location ~ \.php$ {root html;fastcgi_pass 10.20.29.36:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;include fastcgi_params;}access_log /var/log/nginx/access.php.log main;}注意
location / {root /usr/share/nginx/html; //修改这里的默认路径为nginx静态页面路径fastcgi_pass 10.20.29.93:9000;
#这里可以用容器ID,容器名称容器IP端口或者宿主机IP端口都可以找到php服务
即fastcgi_pass 7750e24826b7/php/172.17.0.3/10.20.29.93:9000; 进入到容器里面重新加载配置文件
[rootlocalhost conf]# docker exec -it nginx bash #进入nginx容器
root850e27b026be:/# nginx -t #nginx检测配置文件是否正确
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root850e27b026be:/# nginx -s reload #平滑重启nginx不影响nginx服务使用
3.4 php测试静态页编写
在主机/opt/app/nginx/html 目录下创建php测试页面会直接映射到容器里面
[rootlocalhost html]# pwd
/opt/app/nginx/html[rootlocalhost html]# vim index.php?phpinfo();
?
四、访问浏览器测试
看到php静态测试页面说明搭建成功了