基本环境准备
•创建虚拟机,并配置防火墙、SELINUX、主机名、IP地址、yum
[root@zzgrhel8 ~]# vm clone web1 # 克隆一台7版本的虚拟机
[root@zzgrhel8 ~]# virsh console web1 # 访问虚拟机的控制台
localhost login: root
Password: a
执行以下命令初始化
hostnamectl set-hostname web1
nmcli connection modify eth1 ipv4.method manual ipv4.addresses 192.168.99.11/24
nmcli connection down eth1
nmcli connection up eth1
echo a | passwd --stdin root
退出控制台,以ssh方式登陆
[root@localhost ~]# logout
CentOS Linux 7 (Core)
Kernel 3.10.0-862.el7.x86_64 on an x86_64
web1 login: # 按ctrl+]退回到真机
以ssh方式登陆
[root@zzgrhel8 ~]# ssh 192.168.99.11
[root@web1 ~]# cat /etc/yum.repos.d/local.repo
[local_repo]
name=CentOS-$releasever - Base
baseurl=ftp://192.168.99.240/dvd
enabled=1
gpgcheck=0
配置nginx
•nginx安装及基本配置
[root@web1 ~]# yum -y install gcc openssl-devel pcre-devel
[root@zzgrhel8 ~]# scp /linux-soft/2/lnmp_soft.tar.gz 192.168.99.11:/root
[root@web1 ~]# tar xf lnmp_soft.tar.gz
[root@web1 ~]# cd lnmp_soft/
[root@web1 lnmp_soft]# tar xf nginx-1.12.2.tar.gz
[root@web1 lnmp_soft]# cd nginx-1.12.2/
[root@web1 nginx-1.12.2]# ./configure --with-http_ssl_module --with-http_stub_status_module
[root@web1 nginx-1.12.2]# make && make install
•安装数据库,并配置php支持连接数据库
[root@web1 ~]# yum install -y mariadb-server mariadb-devel php php-fpm php-mysql
•配置服务
mariadb数据库服务
[root@web1 ~]# systemctl enable mariadb.service --now
[root@web1 ~]# ss -tlnp | grep :3306
LISTEN 0 50 *:3306
php-fpm服务,处理php动态程序
[root@web1 ~]# systemctl enable php-fpm.service --now
[root@web1 ~]# ss -tlnp | grep :9000
LISTEN 0 128 127.0.0.1:9000
配置nginx
[root@web1 ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The Nginx HTTP Server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT ${MAINPID}
[Install]
WantedBy=multi-user.target
[root@web1 ~]# systemctl enable nginx --now
[root@web1 ~]# ss -tlnp | grep :80
LISTEN 0 128 *:80
•修改nginx配置文件,实现动静分离
[root@web1 ~]# vim /usr/local/nginx/conf/nginx.conf
... ...
43 location / {
44 root html;
45 index index.php index.html index.htm;
46 }
... ...
65 location ~ .phpfastcgi_scri pt_name;
70 include fastcgi.conf;
71 }
[root@web1 ~]# systemctl restart nginx # 重启服务
配置数据库服务器
•创建程序所需的数据库
•授权用户可以访问数据库
[root@web1 ~]# mysql
创建名为wordpress的数据库,字符编码采用utf8mb4
MariaDB [(none)]> create database wordpress character set utf8mb4;
创建名为wordpress的用户,可以对wordpress拥有全部权限,他的登录密码也是wordpress。该用户既可以在本机登录,也可以在其他客户端地址登录。
MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by 'wordpress';
MariaDB [(none)]> grant all on wordpress.* to wordpress@'192.168.99.11' identified by 'wordpress';
MariaDB [(none)]> grant all on wordpress.* to wordpress@'%' identified by 'wordpress';
MariaDB [(none)]> flush privileges; # 刷新权限
测试账号连接数据库
-u指定数据库账户名称,-p指定数据库账户的密码,-h指定需要远程数据库的IP地址
[root@web1 ~]# mysql -uwordpress -pwordpress -h192.168.99.11 wordpress
部署wordpress
• 复制程序文件到nginx工作目录
解压 [root@web1 ~]# cd lnmp_soft/
[root@web1 lnmp_soft]# yum install -y unzip
[root@web1 lnmp_soft]# unzip wordpress.zip
[root@web1 lnmp_soft]# cd wordpress/
[root@web1 wordpress]# tar xf wordpress-5.0.3-zh_CN.tar.gz
[root@web1 wordpress]# cd wordpress/
[root@web1 wordpress]# cp -r * /usr/local/nginx/html/
php程序是由php-fpm处理的,php-fpm以apache身份运行
[root@web1 wordpress]# ps aux | grep php-fpm
为了让php-fpm程序能对html目录进行读写操作,需要为他授予权限
[root@web1 wordpress]# chown -R apache:apache /usr/local/nginx/html
• 访问http://192.168.99.11/readme.html可以查阅wordpress使用说明
• 访问http://192.168.99.11/进行初始化,它将自动跳转到http://192.168.99.11/wp-admin/setup-config.php
