一、準(zhǔn)備工作
在騰訊云上安裝WordPress前,您需要完成以下準(zhǔn)備工作:
購買騰訊云服務(wù)器:推薦選擇CentOS 7.x或Ubuntu 18.04/20.04系統(tǒng)的云服務(wù)器,1核2G配置即可滿足小型WordPress站點(diǎn)需求。
域名準(zhǔn)備:建議提前注冊好域名并完成備案(國內(nèi)服務(wù)器必須備案)。
連接工具:準(zhǔn)備SSH連接工具如PuTTY(Windows)或終端(Mac/Linux)。
二、環(huán)境配置
方法一:使用寶塔面板快速搭建
- 安裝寶塔面板:
# CentOS系統(tǒng)
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
# Ubuntu系統(tǒng)
wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh
登錄寶塔面板:安裝完成后會顯示面板地址和賬號密碼,通過瀏覽器訪問。
安裝LNMP環(huán)境:在寶塔面板中一鍵安裝Nginx、MySQL和PHP(推薦PHP 7.4)。
方法二:手動安裝LNMP環(huán)境
- 安裝Nginx:
# CentOS
yum install nginx -y
systemctl start nginx
systemctl enable nginx
# Ubuntu
apt install nginx -y
systemctl start nginx
systemctl enable nginx
- 安裝MySQL:
# CentOS
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
yum install mysql-server -y
systemctl start mysqld
systemctl enable mysqld
# Ubuntu
apt install mysql-server -y
systemctl start mysql
systemctl enable mysql
- 安裝PHP:
# CentOS
yum install epel-release yum-utils -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum-config-manager --enable remi-php74
yum install php php-fpm php-mysqlnd php-opcache php-gd php-xml php-mbstring -y
systemctl start php-fpm
systemctl enable php-fpm
# Ubuntu
apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip -y
systemctl start php7.4-fpm
systemctl enable php7.4-fpm
三、創(chuàng)建數(shù)據(jù)庫
- 登錄MySQL:
mysql -u root -p
- 創(chuàng)建WordPress數(shù)據(jù)庫:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
四、下載并安裝WordPress
- 下載最新版WordPress:
cd /var/www
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
chown -R www-data:www-data /var/www/wordpress
chmod -R 755 /var/www/wordpress
- 配置Nginx:
server {
listen 80;
server_name yourdomain.com;
root /var/www/wordpress;
index index.php index.html index.htm;
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;
}
}
- 重啟Nginx:
systemctl restart nginx
五、完成WordPress安裝
訪問您的域名,按照WordPress安裝向?qū)瓿砂惭b。
填寫數(shù)據(jù)庫信息:
- 數(shù)據(jù)庫名:wordpress
- 用戶名:wordpressuser
- 密碼:password
- 數(shù)據(jù)庫主機(jī):localhost
- 表前綴:wp_(建議修改為其他前綴增強(qiáng)安全性)
- 設(shè)置網(wǎng)站標(biāo)題、管理員賬號和密碼。
六、騰訊云額外配置
安全組設(shè)置:在騰訊云控制臺確保開放80(HTTP)和443(HTTPS)端口。
CDN加速:可配置騰訊云CDN加速網(wǎng)站訪問。
對象存儲:建議將媒體文件存儲在騰訊云COS中,減輕服務(wù)器負(fù)擔(dān)。
常見問題解決
502 Bad Gateway錯誤:檢查PHP-FPM是否運(yùn)行,Nginx配置是否正確。
無法創(chuàng)建wp-config.php文件:手動復(fù)制wp-config-sample.php為wp-config.php并填寫數(shù)據(jù)庫信息。
內(nèi)存不足:可通過
wp-config.php
添加define('WP_MEMORY_LIMIT', '256M');
增加內(nèi)存限制。
通過以上步驟,您已成功在騰訊云服務(wù)器上安裝了WordPress。接下來可以開始安裝主題、插件,發(fā)布內(nèi)容,打造您的專屬網(wǎng)站!