準(zhǔn)備工作
在開(kāi)始設(shè)置之前,您需要確保已完成以下準(zhǔn)備工作:
- 已購(gòu)買阿里云ECS服務(wù)器(建議選擇CentOS或Ubuntu系統(tǒng))
- 已完成域名注冊(cè)和備案(國(guó)內(nèi)服務(wù)器必須備案)
- 擁有服務(wù)器root權(quán)限或管理員賬號(hào)
第一步:連接服務(wù)器
使用SSH工具(如PuTTY或Xshell)連接到您的阿里云服務(wù)器:
ssh root@your_server_ip
輸入密碼后即可登錄服務(wù)器。
第二步:安裝LAMP/LNMP環(huán)境
WordPress需要Web服務(wù)器、數(shù)據(jù)庫(kù)和PHP環(huán)境支持,我們推薦以下兩種方案:
方案一:使用寶塔面板(推薦新手)
- 安裝寶塔面板:
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
- 安裝完成后,按提示訪問(wèn)面板地址,安裝LNMP或LAMP環(huán)境
方案二:手動(dòng)安裝LNMP環(huán)境
- 安裝Nginx:
yum install nginx -y
systemctl start nginx
systemctl enable nginx
- 安裝MySQL:
yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
- 安裝PHP:
yum install epel-release yum-utils -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php74
yum install php php-mysql php-fpm php-gd php-mbstring -y
第三步:創(chuàng)建數(shù)據(jù)庫(kù)
登錄MySQL為WordPress創(chuàng)建專用數(shù)據(jù)庫(kù):
mysql -u root -p
CREATE DATABASE wordpressdb;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
exit
第四步:下載并安裝WordPress
- 下載最新版WordPress:
cd /var/www/html
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
- 配置WordPress:
cd wordpress
cp wp-config-sample.php wp-config.php
nano wp-config.php
修改數(shù)據(jù)庫(kù)連接信息:
define('DB_NAME', 'wordpressdb');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'your_password');
第五步:配置Web服務(wù)器
使用寶塔面板:
- 添加站點(diǎn),選擇PHP版本
- 設(shè)置域名和根目錄(指向/var/www/html/wordpress)
手動(dòng)配置Nginx:
編輯Nginx配置文件:
server {
listen 80;
server_name yourdomain.com;
root /var/www/html/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
重啟Nginx:
systemctl restart nginx
第六步:完成安裝
- 訪問(wèn)您的域名,按照WordPress安裝向?qū)瓿砂惭b
- 設(shè)置管理員賬號(hào)和密碼
- 登錄后臺(tái)開(kāi)始使用
常見(jiàn)問(wèn)題解決
- 權(quán)限問(wèn)題:確保/var/www/html/wordpress目錄權(quán)限正確
chown -R nginx:nginx /var/www/html/wordpress
chmod -R 755 /var/www/html/wordpress
無(wú)法上傳文件:修改php.ini中的upload_max_filesize和post_max_size值
固定鏈接404:檢查Nginx配置中的rewrite規(guī)則是否正確
安全建議
- 定期更新WordPress核心、主題和插件
- 安裝安全插件如Wordfence
- 配置防火墻規(guī)則,限制訪問(wèn)
- 定期備份網(wǎng)站和數(shù)據(jù)庫(kù)
通過(guò)以上步驟,您已成功在阿里云服務(wù)器上部署了WordPress網(wǎng)站。如需進(jìn)一步優(yōu)化,可考慮配置HTTPS、CDN加速和對(duì)象存儲(chǔ)等高級(jí)功能。