在Debian系统中搭建WordPress博客可以分为几个主要步骤:安装LAMP环境、配置域名和HTTPS、下载并解压WordPress、配置WordPress以及完成安装。以下是详细的步骤:
首先,确保你的Debian系统是最新的:
sudo apt update
sudo apt upgrade -y
然后,安装Apache、MariaDB和PHP:
sudo apt install apache2 mariadb-server php libapache2-mod-php php-mysql -y
安装完成后,启动并启用MariaDB服务,并运行安全脚本来设置root密码和其他安全选项:
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
编辑Apache的默认站点配置文件:
sudo nano /etc/apache2/sites-available/000-default.conf
在<VirtualHost *:80>
块中添加以下内容:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
保存并退出编辑器,然后重启Apache:
sudo systemctl restart apache2
从WordPress官方网站下载最新版本的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
打开浏览器并访问你的服务器IP地址或域名,按照WordPress安装向导完成安装。你需要输入之前创建的数据库名称、用户名和密码。
安装完成后,删除wp-config-sample.php
文件:
sudo rm wp-config-sample.php
为了提高安全性,建议使用SSL证书。你可以使用Let’s Encrypt免费获取SSL证书:
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d yourdomain.com
按照提示完成SSL证书的安装和配置。
如果你启用了防火墙,确保允许HTTP和HTTPS流量:
sudo ufw allow 'Apache Full'
现在,你的WordPress博客应该已经成功部署在Debian服务器上了。你可以通过浏览器访问你的域名或IP地址来查看你的博客。