ArchLinux服务器手动搭建wordpress
  • 视频里忘了一个步骤,得先解析域名到服务器IP,腾讯云里自带有
  • 安装所需软件包
pacman -S nginx mariadb php php-fpm
  • 配置mariadb
# 初始化数据库
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
# 启用并启动mariadb服务
systemctl enable --now mariadb
# 安全设置
mysql_secure_installation
# 登录mariadb数据库
mysql -u root -p
# 创建数据库
CREATE DATABASE 数据库名; # 修改这里
# 创建数据库用户并授权
GRANT ALL PRIVILEGES ON 数据库名.* TO '用户名'@'localhost' IDENTIFIED BY '密码'; # 修改这里
# 刷新权限
FLUSH PRIVILEGES;
# 退出数据库
EXIT;
  • 配置nginx
# 编辑nginx配置文件
echo '' > /etc/nginx/nginx.conf && nano /etc/nginx/nginx.conf
# 写入nginx配置内容
user http;
worker_processes auto;

events {
    worker_connections 2048;  #CPU核心数*1024
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    client_max_body_size 1000m;  # 上传限制参数,允许上传1GB以内的文件

    types_hash_max_size 2048;
    types_hash_bucket_size 128;

    # HTTP server
    server {
        listen 80;
        server_name 域名;  # 修改这里

        # 重定向所有HTTP请求到HTTPS
        return 301 https://$host$request_uri;
    }

    # HTTPS server
    server {
        listen 443 ssl;
        server_name 域名;  # 修改这里

        http2 on;

        # 证书位置
        ssl_certificate /etc/nginx/certs/blog/cert.pem;
        ssl_certificate_key /etc/nginx/certs/blog/key.pem;

        # 网站源文件路径
        root /var/www/blog; 
        index index.php;

        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

        # 优化安全性
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
        ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';

        # 安全头部配置
        add_header X-Frame-Options SAMEORIGIN;
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";

        # 防止点击劫持
        add_header Content-Security-Policy "frame-ancestors 'self';";

        try_files $uri $uri/ /index.php?$args;

        # PHP-FPM配置
        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        # 禁止访问敏感文件
        location ~* \.(htaccess|htpasswd|env|ini|phar|sh|sql|bak)$ {
            deny all;
        }

        # 添加缓存控制头部来优化静态资源的加载
        location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
            expires 7d;
        }

    }
}
  • 申请SSL证书并下载,这里面的证书位置和nginx配置上的要一致,路径可以自己改
pacman -S cron socat
# 申请证书
curl https://get.acme.sh | sh 
~/.acme.sh/acme.sh --register-account -m 邮箱    # 修改这里
~/.acme.sh/acme.sh --issue -d 域名 --standalone  # 修改这里
# 下载证书
mkdir -p /etc/nginx/certs/blog
~/.acme.sh/acme.sh --installcert -d 域名 --key-file /etc/nginx/certs/blog/key.pem --fullchain-file /etc/nginx/certs/blog/cert.pem    # 修改这里
  • 下载wordpress
pacman -S wget unzip
mkdir /var/www && cd /var/www
wget https://cn.wordpress.org/wordpress-latest-zh_CN.zip
unzip wordpress-latest-zh_CN.zip
rm wordpress-latest-zh_CN.zip
chmod -R 777 /var/www/
mv wordpress blog
  • PHP配置
# 编辑PHP配置文件
nano /etc/php/php.ini
# 取消注释下面两行
extension=pdo_mysql
extension=mysqli
  • 开机自启服务
# 启用并自启php-fpm服务
systemctl enable --now php-fpm
# 启用并自启nginx服务
systemctl enable --now nginx
  • 访问设置的域名,开始配置wrodpress
  • 强制 WordPress 使用直接文件系统方法(direct)进行更新和安装
nano /var/www/blog/wp-config.php
# 必须先访问域名配置好wordpress,出现wordpress控制页面后,才能添加下面内容
define('FS_METHOD', 'direct');
  • wrodpress的部分功能可能还需要用到其他的php拓展,可以直接编辑php.ini取消注释,部分拓展需要去Arch软件库搜索”php-“查找
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇