Categories
Uncategorized

LNMP搭建wordpress

一、安装mysql8.0

yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
yum install mysql-community-server
service mysqld start
service mysqld status

1.查看初始密码

grep 'temporary password' /var/log/mysqld.log

2.修改登录密码

mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';

二、安装php7.2

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-mysql php72w-fpm

查看php版本列表

yum list php*

三、安装nginx

yum install nginx
systemctl start nginx
systemctl enable nginx.service 

1.修改nginx.conf配置

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  binnear.com.cn; # 此处修改为你的域名或者公网IP
    root         /usr/share/nginx/html; # 你的站点的目录

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$args;
    }

    rewrite /wp-admin$ $scheme://$host$uri/ permanent;

    location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
                access_log off; log_not_found off; expires max;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

2.重启nginx

systemctl reload nginx

3.检查是否成功

vim /usr/share/nginx/html/index.php
<?php
    echo "<title>Test Page</title>";
    echo "Hello World!";
?>

四、安装wordpress

wget https://wordpress.org/latest.tar.gz
tar zxvf wordpress-5.3.2.tar.gz
cd wordpress
cp wp-config-sample.php wp-config.php

1.修改wp-config配置

vim wp-config.php
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress'); # 数据库名

/** MySQL database username */
define('DB_USER', 'root');  # 数据库用户名

/** MySQL database password */
define('DB_PASSWORD', '123456');    # 数据库密码

/** MySQL hostname */
define('DB_HOST', 'localhost'); # 一般不修改

2.移到网站目录

rm /usr/share/nginx/html/index.html
mv * /usr/share/nginx/html/

五、mysql8.0遇到的坑

PHP Warning:  mysqli_connect(): Headers and client library minor version mismatch. Headers:50564 Library:50645 in /usr/share/nginx/wordpress/test.php on line 2
PHP Warning:  mysqli_connect(): (HY000/2059): Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory in /usr/share/nginx/wordpress/test.php on line 2

安装完报错,是因为mysql8.0默认的身份校验插件从mysql_native_password 变为caching_sha2_password,php不支持新插件,导致不能通过身份校验

解决mysql8.0的坑

对当前用户有效

ALTER USER 'wp_cli_test'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password1';

对新增用户有效

vim /etc/my.conf
default_authentication_plugin=mysql_native_password
systemctl restart mysqld

Leave a Reply

Your email address will not be published. Required fields are marked *