WordPress作為全球最流行的內(nèi)容管理系統(tǒng)(CMS),搭建個(gè)人博客或企業(yè)網(wǎng)站都非常方便。本文將詳細(xì)介紹如何在LNMP(Linux+Nginx+MySQL+PHP)環(huán)境下快速部署WordPress。
一、LNMP環(huán)境準(zhǔn)備
首先確保服務(wù)器已安裝LNMP環(huán)境:
- Linux系統(tǒng):推薦使用CentOS 7/8或Ubuntu 18.04/20.04
- Nginx安裝:
sudo apt install nginx # Ubuntu/Debian
sudo yum install nginx # CentOS
- MySQL安裝:
sudo apt install mysql-server mysql-client
sudo mysql_secure_installation
- PHP安裝:
sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-zip
二、創(chuàng)建WordPress數(shù)據(jù)庫
登錄MySQL并創(chuàng)建專用數(shù)據(jù)庫:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;
EXIT;
三、下載并配置WordPress
- 下載最新版WordPress:
cd /var/www
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz
sudo chown -R www-data:www-data wordpress
- 配置Nginx虛擬主機(jī):
server {
listen 80;
server_name yourdomain.com;
root /var/www/wordpress;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
四、完成WordPress安裝
- 重啟Nginx服務(wù):
sudo systemctl restart nginx
- 訪問您的域名,按照WordPress安裝向?qū)瓿膳渲茫?/li>
- 填寫之前創(chuàng)建的數(shù)據(jù)庫信息
- 設(shè)置網(wǎng)站標(biāo)題、管理員賬號(hào)等信息
五、常見問題解決
- 文件權(quán)限問題:
sudo chmod -R 755 /var/www/wordpress
sudo chown -R www-data:www-data /var/www/wordpress
PHP擴(kuò)展缺失: 確保已安裝所有必要PHP擴(kuò)展,可通過
php -m
查看Nginx 404錯(cuò)誤: 檢查Nginx配置中的
try_files
指令是否正確
六、安全加固建議
- 限制wp-admin目錄訪問
- 安裝WordPress安全插件如Wordfence
- 定期備份網(wǎng)站和數(shù)據(jù)庫
- 保持WordPress核心、主題和插件為最新版本
通過以上步驟,您已成功在LNMP環(huán)境下部署了WordPress網(wǎng)站。接下來可以根據(jù)需要選擇主題、安裝插件,開始您的內(nèi)容創(chuàng)作之旅。