丝袜av在线观看|日本美女三级片在线播放|性欧美一区二区三区|小骚热免费国产视频|黑人va在线观看|女同国产91视频|五月丁香色播Av|国产凸凹视频一区二区|伊人电影久久99|国产成人无码一区二区观看

LNMP+WordPress快速部署個(gè)人網(wǎng)站指南

來自:素雅營銷研究院

頭像 方知筆記
2025年06月02日 10:45

一、LNMP環(huán)境簡介

LNMP代表Linux+Nginx+MySQL+PHP,是目前搭建WordPress網(wǎng)站最流行的服務(wù)器環(huán)境組合之一。相比傳統(tǒng)的LAMP(Apache替代Nginx),LNMP架構(gòu)具有更高的并發(fā)處理能力和更低的內(nèi)存消耗,特別適合個(gè)人網(wǎng)站和小型項(xiàng)目。

二、準(zhǔn)備工作

在開始部署前,您需要準(zhǔn)備:

  1. 一臺(tái)Linux服務(wù)器(推薦CentOS 7/8或Ubuntu 18.04/20.04)
  2. SSH客戶端工具(如PuTTY或終端)
  3. 域名(可選,可通過IP直接訪問)
  4. 基本的Linux命令行操作知識(shí)

三、LNMP環(huán)境安裝

1. 安裝Nginx

對(duì)于CentOS系統(tǒng):

sudo yum install epel-release
sudo yum install nginx
sudo systemctl start nginx
sudo systemctl enable nginx

對(duì)于Ubuntu系統(tǒng):

sudo apt update
sudo apt install nginx
sudo systemctl start nginx
sudo systemctl enable nginx

安裝完成后,在瀏覽器輸入服務(wù)器IP,應(yīng)能看到Nginx歡迎頁面。

2. 安裝MySQL/MariaDB

CentOS:

sudo yum install mariadb-server mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation

Ubuntu:

sudo apt install mariadb-server
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation

執(zhí)行安全安裝腳本時(shí),建議設(shè)置root密碼并移除測試數(shù)據(jù)庫和匿名用戶。

3. 安裝PHP

CentOS 7:

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum install yum-utils
sudo yum-config-manager --enable remi-php74
sudo yum install php php-mysqlnd php-fpm php-gd php-mbstring php-xml php-curl

Ubuntu:

sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip

安裝完成后,啟動(dòng)PHP-FPM服務(wù):

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

四、配置Nginx支持PHP

編輯Nginx配置文件(通常位于/etc/nginx/conf.d/default.conf或/etc/nginx/sites-available/default):

server {
listen       80;
server_name  yourdomain.com; # 替換為您的域名或IP

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

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

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

測試配置并重啟Nginx:

sudo nginx -t
sudo systemctl restart nginx

五、安裝WordPress

1. 創(chuàng)建數(shù)據(jù)庫

登錄MySQL:

mysql -u root -p

創(chuàng)建WordPress數(shù)據(jù)庫和用戶:

CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

2. 下載并安裝WordPress

cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz
sudo chown -R nginx:nginx /var/www/html
sudo chmod -R 755 /var/www/html

3. 完成WordPress安裝

在瀏覽器訪問您的服務(wù)器IP或域名,按照WordPress安裝向?qū)瓿砂惭b:

  1. 選擇語言
  2. 輸入之前創(chuàng)建的數(shù)據(jù)庫信息
  3. 設(shè)置網(wǎng)站標(biāo)題、管理員賬號(hào)和密碼
  4. 完成安裝并登錄后臺(tái)

六、基本優(yōu)化與安全設(shè)置

  1. 設(shè)置固定鏈接:在WordPress后臺(tái) > 設(shè)置 > 固定鏈接,選擇”文章名”格式
  2. 安裝必要插件
  • 安全插件:Wordfence或iThemes Security
  • 緩存插件:WP Super Cache或W3 Total Cache
  • SEO插件:Yoast SEO或Rank Math
  1. 配置防火墻
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
  1. 啟用HTTPS:申請(qǐng)免費(fèi)SSL證書(如Let’s Encrypt)并配置

七、常見問題解決

  1. 502 Bad Gateway錯(cuò)誤:檢查PHP-FPM是否運(yùn)行,以及Nginx配置中的fastcgi_pass路徑是否正確
  2. 文件上傳權(quán)限問題:確保/var/www/html目錄權(quán)限正確
  3. 數(shù)據(jù)庫連接錯(cuò)誤:檢查wp-config.php中的數(shù)據(jù)庫信息是否正確

通過以上步驟,您已成功使用LNMP架構(gòu)部署了WordPress網(wǎng)站。后續(xù)可以根據(jù)需求進(jìn)行主題定制、插件安裝和內(nèi)容創(chuàng)作,打造專屬的個(gè)人網(wǎng)站。