LNMP搭建WordPress
链接:https://pan.baidu.com/s/1yRtV7Z0H466Qp8aKIKrOlQ
提取码:rvhv
1、 环境准备
1.1、 Centos7虚拟机一台
1.2、 把lnmp.tar.gz上传到centos
1.3、 解压lnmp.tar.gz到/opt/下
[root@localhost ~]# tar -zxvf lnmp.tar.gz -C /opt/
1.4、 配置yum
将原本的yum移走到/home
[root@localhost ~]# mv /etc/yum.repo.d/* /home/
编写配置文件lnmp.repo
[root@localhost ~]# vi /etc/yum.repo.d/lnmp.repo
内容:
[lnmp]
name=lnmp
baseurl=file:///opt/lnmp
gpgcheck=0
enabled=1
检查是否有用
[root@localhost ~]# yum repolist
1.5、 关闭防火墙
[root@localhost ~]# systemctr stop firewalld
[root@localhost ~]# systemctr disable firewalld
关闭selinux
[root@localhost ~]# vi /etc/sysconfig/selinux
SELINUX=disabled
2、 部署MySQL服务
[root@localhost ~]# yum -y install mariadb-server
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb
安装成功可以使用没有密码
3、 部署Nginx服务
老版本centos7中yum源中没有Nginx包,新版本有包。本实验使用自己的本地yum安装。
[root@localhost ~]# yum -y install nginx
查看版本为1.6
[root@localhost ~]# nginx -v
nginx version: nginx/1.16.1
4、 部署PHP服务
[root@localhost ~]# yum -y install php
查看版本
Centos7安装默认为5版本
[root@localhost ~]# php -v
PHP 5.4.16 (cli) (built: Apr 1 2020 04:07:17)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
查看是否有该目录有这成功安装
5、 修改Nginx配置文件
路径:/etc/nginx/nginx.conf
修改为
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
index index.php index.html;
server_name _;
root /usr/share/nginx/html;
index index.php index.html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /var/www/html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 8080 default_server;
listen [::]:8080 default_server;
index index.php index.html;
server_name _;
root /usr/share/nginx/html;
index index.php index.html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /404.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
配置文件:nginx.conf
6、 Nginx服务默认不支持PHP文件,需要安装php-fpm服务:
[root@localhost ~]# yum -y install php-fpm
[root@localhost ~]# systemctl restart php-fpm
7、 启动Nginx服务
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
8、 安装PHP连接数据库的中间件
[root@localhost ~]# yum -y install php-mysql php-gd
配置MySQL支持中文:
[root@localhost ~]# vi /etc/my.cnf
character-set-server=utf8
重启服务
[root@localhost ~]# systemctl restart mariadb php-fpm
9、 部署WordPress博客
9.1、安装所需插件
[root@localhost ~]# yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
9.2、解压WordPress压缩包
[root@localhost ~]# cd /opt/
[root@localhost opt]# unzip wordpress-zh_CN.zip
9.3、部署WordPress环境
[root@localhost opt]# rm -rf /usr/share/nginx/html/*
[root@localhost opt]# cp -r wordpress/* /usr/share/nginx/html/
[root@localhost opt]# chmod 777 -R /usr/share/nginx/html/wp-content/
9.4、创建数据库并设置访问权限
[root@localhost ~]# mysql -uroot -p
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> grant all privileges on *.* to root@localhost identified by '000000' with grant option;
MariaDB [(none)]> grant all privileges on *.* to root@"%" identified by '000000' with grant option;
9.5、浏览器访问http://IP:8080
9.6、配置数据库连接
配置数据如图
9.7、编辑wp-config.Php
出现如下图则需自己配置文件
路径:/usr/share/nginx/html/
[root@localhost ~]# cd /usr/share/nginx/html/
可以发现是没有wp-config.php文件的,需要将wp-config-sample.php复制并命名为wp-config.php 才能行。
[root@localhost html]# cp wp-config-sample.php wp-config.php
修改wp-config.php内容
[root@localhost html]# vim wp-config.php
根据下图填写上面内容
完成后点击进行安装
出现下图,
填写完成后进行安装。
登录
完成部署安装WordPress