1 安装LNMP四件套

先安装LNMP四件套(Linux、Nginx、MaraiDB/MySQL、PHP)

安装Mariadb

cloud@server:~ $ sudo apt install -y mariadb-server

Nginx和PHP8.0已安装,见玩转树莓派(二)

2 部署WoredPress

2.1 配置Nginx

cloud@server:/var/www/html $ cd /etc/nginx/sites-available/
cloud@server:/etc/nginx/sites-available $ sudo vim blog

创建文件

server {
    listen 55105;
    root /var/www/blog/html;
    index index.html index.htm index.nginx-debian.html index.php;

    server_name blog.tangke8.com;

    location / {
    index  index.html index.htm index.php default.html default.htm default.php;
    }   

    location ~\.php$ {
    fastcgi_pass unix:/run/php/php8.0-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
}

创建符号链接

cloud@server:/etc/nginx/sites-available $ sudo ln -s /etc/nginx/sites-available/blog /etc/nginx/sites-enabled/blog

重启Nginx服务

cloud@server:/etc/nginx/sites-available $ sudo service nginx restart

2.2 设置数据库

cloud@server:/etc/nginx/sites-available $ su -
root@server:~# mysql -u root -p
输入安装时设置的密码

MariaDB [(none)]>  CREATE DATABASE wordpress;

MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"localhost" IDENTIFIED BY "passwd";

MariaDB [(none)]> FLUSH PRIVILEGES;

MariaDB [(none)]> EXIT

2.3 下载安装WordPress

root@server:~# exit
cloud@server:/etc/nginx/sites-available sudo mkdir -p /var/www/blog/
cloud@server:/etc/nginx/sites-available cd /var/www/blog/
cloud@server:/var/www/blog $ sudo wget https://cn.wordpress.org/latest-zh_CN.tar.gz
cloud@server:/var/www/blog $ sudo tar zxf latest-zh_CN.tar.gz
cloud@server:/var/www/blog $ sudo mv wordpress/ html
cloud@server:/var/www/blog $ sudo chown -R www-data:www-data html/
cloud@server:/var/www/blog $ cd html/
cloud@server:/var/www/blog/html $ sudo cp wp-config-sample.php wp-config.php
cloud@server:/var/www/blog/html $ sudo vim wp-config.php

修改如下内容

define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', 'passwd');

修改权限

cloud@server:/var/www/blog/html $ sudo mkdir wp-content/uploads
cloud@server:/var/www/blog/html $ sudo chmod 755 / wp-includes wp-admin wp-admin/js wp-content wp-content/themes wp-content/plugins wp-content/uploads
cloud@server:/var/www/blog/html $ sudo chmod 444 wp-config.php

3 映射到公网ip

3.1 添加主机名映射

在阿里云主机上

cloud@aliyun:~$ sudo vim /etc/hosts

增加一行

127.0.0.1       blog.tangke8.com

3.2 增加域名解析

在阿里云控制台上增加对子域名blog的解析

https://swas.console.aliyun.com/

3.3 增加frp映射

cloud@server:/etc/nginx/sites-available $ cd /opt/module/frp/
cloud@server:/opt/module/frp $ vim frpc.ini

增加一行

[web-blog]
type = http
local_ip = 127.0.0.1
local_port = 55105
custom_domains = blog.tangke8.com

重启frpc服务

cloud@server:/opt/module/frp $ ps -ef|grep frpc
cloud@server:/opt/module/frp $ sudo kill -9 xxxxx
cloud@server:/opt/module/frp $ sudo nohup /opt/module/frp/frpc -c /opt/module/frp/frpc.ini >> /opt/module/frp/frpc.log 2>&1 &

在浏览器输入 https://blog.tangke8.com/wp-admin/install.php 验证是否成功