centOS8.2部署LNMP+wordPress

一、简介

-L:Linux操作系统

-N:Nginx网站服务软件

-M:MySQL、MariaDB数据库

-P:网站开发语言(PHP、Perl、Python)

主要介绍在centos8.2版本Linux实例搭建LNMP平台,并部署wordPress环境。

操作步骤如下

1.安装Nginx

ss -tunlp | grep :80  //查看80端口是否被占用
注意:安装前httpd服务不能启动,80端口不能被占用;如有占用要将进程进行结束
yum -y install nginx  #安装nginx
systemctl enable nginx --now #启动nginx并设置开机自启

使用浏览器访问:http://服务器IP

  若能出现如下界面则说明nginx安装成功

centOS8.2部署LNMP+wordPress_第1张图片

2.安装MySQL

[root@ecs-77944 ~]# wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm   #下载源
[root@ecs-77944 ~]# rpm -ivh mysql80-community-release-el8-1.noarch.rpm
[root@ecs-77944 ~]# md5sum mysql80-community-release-el8-1.noarch.rpm     #MD5效验
[root@ecs-77944 ~]# yum -y install mysql-server         #安装mysql
[root@ecs-77944 ~]# systemctl enable mysqld --now     #启动mysql并设置开机自启
[root@ecs-77944 ~]# systemctl status mysqld           #查看启动状态

安全配置
在设置密码的过程中,总共有五步:
#1.设置 root 密码;
#2.是否禁止匿名账号(anonymous)登录;
#3.是否禁止 root 账号远程登录;
#4.是否删除测试库;
#5.是否确认修改。

[root@ecs-77944 ~]# mysql_secure_installation

 Press y|Y for Yes, any other key for No: y

 New password:           #输入密码

 Re-enter new password:  #输入新的密码

 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
 
 Remove anonymous users? (Press y|Y for Yes, any other key for No) : y #是否删除匿名用户

 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n #禁止root远程登录

 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y #删除测试库

 Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y #确认修改并加载
 

3.安装PHP

[root@ecs-77944 ~]# yum install php php-devel  #安装php
[root@ecs-77944 ~]# yum install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-json php-mbstring php-bcmath  #安装php扩展,php-json必须安装不然wordpress会有问题
(安装时遇到了错误【Error: Unable to find a match: php-mysql】,没有匹配的参数)

进行匹配版本
[root@ecs-77944 ~]# yum search php-mysql
Last metadata expiration check: 1:39:14 ago on Wed 19 Jan 2022 12:20:42 PM CST.
========================================== Name Matched: php-mysql ==========================================
php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
[root@ecs-77944 ~]# yum -y install php-mysqlnd.x86_64  #匹配版本

[root@ecs-77944 ~]# systemctl enable php-fpm --now     #启动php服务ging设置开机自启动

[root@ecs-77944 ~]# vim /etc/nginx/conf.d/default.conf #添加如下信息
server {
        listen       80;
        server_name  localhost;

        #access_log /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;    }

    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;
    }
  }

[root@ecs-77944 ~]# service nginx reload #重新载入nginx配置文件
[root@ecs-77944 ~]# vim /usr/share/nginx/html/info.php #创建测试页面,输入如下内容
    

使用浏览器访问“http://服务器IP地址/info.php”;显示如下页面,说明环境搭建成功

centOS8.2部署LNMP+wordPress_第2张图片

4.创建数据库

[root@ecs-77944 ~]# mysql -u root -p      #以root身份访问数据库
Enter password:                           #输入密码

CREATE DATABASE mypress;                  #创建数据库
mysql> create user 'myblog'@'localhost' identified by '密码'; #创建用户和密码(密码强度需要大小写及数字字母,否则会报密码强度不符合)
mysql> grant all on mypress.* to 'myblog'@'localhost';        #用户授权 localhost为本地权限
(本系统,分权管理数据)

[root@ecs-77944 ~]# mysql -u myblog -p   #验证数据库和用户是否已成功创建
Enter password:                           #输入密码
mysql> SHOW DATABASES;
mysql> exit
其中,“myblog”为刚刚创建的数据库用户名

5.安装wordpress

①自行下载wordpress(我用的wordpress-5.3.2-zh_CN.tar.gz),并上传至主机

[root@ecs-77944 ~]# tar -xvf wordpress-5.3.2-zh_CN.tar.gz -C /usr/share/nginx/html/ #解压wordpress到/usr/share/nginx/html目录    解压后生成一个“wordpress”的文件夹。

[root@ecs-77944 ~]# chmod -R 777 /usr/share/nginx/html/wordpress 设置文件权限

②浏览器访问“http://服务器IP地址/wordpress”进入安装向导centOS8.2部署LNMP+wordPress_第3张图片

 ③后续按照先关配置参数输入即可

你可能感兴趣的:(应用,linux,运维,centos)