Files
chill_notes/Linux/AliYun/阿里云管理WordPress.md
2026-04-21 20:33:24 +08:00

143 lines
2.4 KiB
Markdown
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 阿里云管理 WordPress
> WordPress 安装与配置
---
## 下载并安装
```bash
# 下载 WordPress
wget https://wordpress.org/latest.zip
# 安装解压工具
apt-get install unzip
# 解压到网站目录
unzip -q latest.zip -d /var/www/html/
cd /var/www/html/wordpress
# 移动文件到根目录
cp -a * ..
rm -rf wordpress/
# 设置权限
chown www-data:www-data -R /var/www/html/
```
---
## 创建上传目录
```bash
mkdir -p /var/www/html/wp-content/uploads
chown www-data:www-data -R /var/www/html/wp-content/uploads
```
---
## 创建数据库
```bash
mysql -u root -p
```
```sql
CREATE DATABASE wordpress CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost' IDENTIFIED BY '你的密码';
FLUSH PRIVILEGES;
EXIT;
```
---
## 配置 WordPress
```bash
cd /var/www/html
mv wp-config-sample.php wp-config.php
vim wp-config.php
```
修改数据库连接:
```php
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', '你的密码');
define('DB_HOST', 'localhost');
```
---
## 配置固定链接
### 1. 修改 Apache 配置
```bash
sudo vim /etc/apache2/sites-available/000-default.conf
```
添加:
```apache
<Directory /var/www/html/>
AllowOverride All
</Directory>
```
### 2. 启用 rewrite 模块并重启
```bash
sudo a2enmod rewrite
sudo systemctl restart apache2
```
### 3. 创建 .htaccess
```bash
touch /var/www/html/.htaccess
chown :www-data /var/www/html/.htaccess
chmod 664 /var/www/html/.htaccess
```
---
## 安全密钥
访问https://api.wordpress.org/secret-key/1.1/salt/
复制生成的密钥,添加到 `wp-config.php`
```php
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
```
---
## 常用命令
```bash
# 重启 Apache
sudo systemctl restart apache2
# 查看 WordPress 文件
ls -la /var/www/html/
# 更新权限
sudo chown -R www-data:www-data /var/www/html/
```
---
## 访问 WordPress
浏览器打开:`http://服务器IP`
按提示完成安装即可。