/usr/local/nginx/usr/local/nginx/html127.0.0.1:9000vim /usr/local/nginx/conf/nginx.conf
# 在 http 段或 server 段確保:
user www www;
index index.php index.html;
# 取消 FastCGI 區塊註釋並調整
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 重啟 Nginx
/usr/local/nginx/sbin/nginx -s reload
cd /usr/local/src
wget https://wordpress.org/latest.tar.gz
tar zxvf latest.tar.gz
# 移動到 Web 根目錄
mv wordpress/* /usr/local/nginx/html/
# 或建立軟連結
# ln -s /usr/local/src/wordpress /usr/local/nginx/html/wp
# 設定權限(Nginx/PHP-FPM 執行用戶為 www)
chown -R www:www /usr/local/nginx/html
chmod -R 755 /usr/local/nginx/html
mysql -u root -p
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'StrongPassw0rd!';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
https://your-domain-or-ip/wordpresswp_userStrongPassw0rd!localhostwp_(可自定義)wp-config.php 設定 define('DISALLOW_FILE_EDIT', true); 禁用後台檔案編輯。wp-content/uploads。add_filter('the_generator', '__return_empty_string');。
location / {
try_files $uri $uri/ /index.php?$args;
}
# 確保上方規則在 server 段內,替換原有 try_files
重啟 Nginx 後,WordPress 後台「設定 → 固定連結」選擇「文章名」即可生效。
源碼編譯 LNMP 環境部署 WordPress 關鍵點:Nginx FastCGI 正確指向 PHP-FPM、Web 目錄權限歸屬 www、資料庫字符集 utf8mb4、固定連結 try_files 規則。完成上述步驟即可擁有高效能、可控的 WordPress 生產站點。