一、準(zhǔn)備工作
在CentOS服務(wù)器上部署WordPress前,需要確保系統(tǒng)環(huán)境滿足基本要求。首先確認(rèn)您的CentOS版本(推薦7.x或8.x),然后更新系統(tǒng)軟件包:
sudo yum update -y
安裝必要的工具和依賴項:
sudo yum install -y wget unzip
二、安裝LAMP環(huán)境
WordPress運(yùn)行需要LAMP(Linux, Apache, MySQL/MariaDB, PHP)環(huán)境支持。
1. 安裝Apache Web服務(wù)器
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
2. 安裝MariaDB數(shù)據(jù)庫
sudo yum install -y mariadb-server mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
3. 安裝PHP及相關(guān)模塊
sudo yum install -y php php-mysqlnd php-gd php-xml php-mbstring
sudo systemctl restart httpd
三、配置數(shù)據(jù)庫
登錄MariaDB創(chuàng)建WordPress專用數(shù)據(jù)庫和用戶:
mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
exit
四、安裝WordPress
1. 下載并解壓WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
sudo mv wordpress /var/www/html/
sudo chown -R apache:apache /var/www/html/wordpress
2. 配置WordPress
cd /var/www/html/wordpress
cp wp-config-sample.php wp-config.php
編輯wp-config.php文件,填入之前創(chuàng)建的數(shù)據(jù)庫信息:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');
五、完成安裝
通過瀏覽器訪問您的服務(wù)器IP或域名,按照WordPress安裝向?qū)瓿勺詈笤O(shè)置:
http://your_server_ip/wordpress
六、安全優(yōu)化建議
- 配置防火墻:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
安裝SSL證書(推薦使用Let’s Encrypt)
定期備份網(wǎng)站和數(shù)據(jù)庫
保持WordPress核心、主題和插件更新
通過以上步驟,您已成功在CentOS服務(wù)器上部署了WordPress網(wǎng)站。接下來可以根據(jù)需要安裝主題、插件,開始創(chuàng)建您的內(nèi)容。