---
title: WordPress 安装及 HTTPS 配置（LNMP）
description: "WordPress 安装及 HTTPS 配置文档，介绍如何在**已配置 SSL/…"
url: "https://brimflow.xyz/docs/operations/debian-lnmp-wordpress-install/"
updated: "2025-08-08"
category: 运维
---

# WordPress 安装及 HTTPS 配置（LNMP）

WordPress 安装及 HTTPS 配置文档，介绍如何在**已配置 SSL/TLS 证书**和**已安装 LNMP**（Linux + Nginx + MariaDB + PHP）的 Debian 服务器上安装 WordPress 及配置 HTTPS。

**前置要求：**

- 已配置 SSL/TLS 证书：[参考 SSL/TLS 证书配置指南](https://brimflow.xyz/docs/operations/debian-certbot-https/)
- 已安装 LNMP 环境：[参考 LNMP 安装指南](https://brimflow.xyz/docs/operations/debian-lnmp-install/)

## 一、配置数据库 (MariaDB)

### 1.1 生成数据库密码

生成一个安全的随机密码，用于 WordPress 数据库用户。请**务必记录此密码** (`WP-DB-PASSWORD`)。

 Bash

```
openssl rand -base64 12
```

### 1.2 创建数据库及用户

进入 MariaDB 控制台：

 Bash

```
sudo mysql -u root -p
```

执行以下 SQL 命令（将 `WP-DB-PASSWORD` 替换为您生成的密码）：

 SQL

```
CREATE DATABASE wordpress_db;
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost' IDENTIFIED BY 'WP-DB-PASSWORD';
FLUSH PRIVILEGES;
EXIT;
```

### 1.3 重置数据库密码 (可选)

如需重置密码，进入 MariaDB 后执行以下 SQL 命令（将 `NEW-PASSWORD` 替换为您希望设置的新密码）：

 SQL

```
ALTER USER 'wordpress_user'@'localhost' IDENTIFIED BY 'NEW-PASSWORD';
FLUSH PRIVILEGES;
EXIT;
```

## 二、配置 PHP (以 PHP 8.2 为例)

### 2.1 修改上传限制

编辑 PHP 配置文件：

 Bash

```
sudo nano /etc/php/8.2/fpm/php.ini
```

修改以下参数（建议值）：

 INI

```
max_execution_time = 330
post_max_size = 128M
upload_max_filesize = 128M
```

保存文件并重启 PHP 服务：

 Bash

```
sudo systemctl restart php8.2-fpm
```

## 三、安装 WordPress

### 3.1 下载并解压

 Bash

```
curl -LO https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
sudo mv wordpress /var/www/
```

### 3.2 配置 WordPress

复制并编辑 WordPress 配置文件：

 Bash

```
sudo cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php
sudo nano /var/www/wordpress/wp-config.php
```

修改以下数据库连接配置（将 `WP-DB-PASSWORD` 替换为您在 **1.1** 步骤中生成的密码）：

 PHP

```
define( 'DB_NAME', 'wordpress_db' );
define( 'DB_USER', 'wordpress_user' );
define( 'DB_PASSWORD', 'WP-DB-PASSWORD' );
define( 'DB_HOST', 'localhost' );
```

设置 WordPress 目录的所有者：

 Bash

```
sudo chown -R www-data:www-data /var/www/wordpress/
```

## 四、配置 Nginx

### 4.1 编辑网站配置文件

以 `xsymm.com` 为例，创建或编辑您的网站配置文件：

 Bash

```
sudo nano /etc/nginx/conf.d/xsymm.com.conf
```

将以下配置粘贴到文件中（请将 `xsymm.com` 替换为您的实际域名，并检查 HTTPS 证书路径是否正确）：

 Nginx

```
server {
    listen 80;
    listen [::]:80;
    server_name xsymm.com www.xsymm.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;

    server_name xsymm.com www.xsymm.com;

    ssl_certificate /etc/letsencrypt/live/xsymm.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/xsymm.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/xsymm.com/chain.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;
    ssl_stapling on;
    ssl_stapling_verify on;

    resolver 8.8.8.8 8.8.4.4 valid=300s;
    resolver_timeout 5s;

    root /var/www/wordpress;
    index index.php index.html index.htm;

    access_log /var/log/nginx/xsymm.com.access.log;
    error_log /var/log/nginx/xsymm.com.error.log warn;

    client_max_body_size 128M;

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

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        include fastcgi_params;
        fastcgi_intercept_errors on;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
```

### 4.2 重启 Nginx

 Bash

```
sudo systemctl restart nginx
```

## WordPress 安装及 HTTPS 配置完成

- 在浏览器中访问您的域名（例如：`https://xsymm.com`）
- 按照 WordPress 安装向导完成剩余的配置
- 设置您的网站标题、管理员用户名、密码和邮箱等信息

 [如何安装 WordPress](https://developer.wordpress.org/advanced-administration/before-install/howto-install/)
