使用Apache2部署WordPress是一个相对简单的过程,以下是在Ubuntu系统上部署WordPress的详细步骤:
首先,确保你的系统是最新的,然后安装Apache2和PHP及其相关模块。
sudo apt update
sudo apt install apache2 php libapache2-mod-php php-mysql
安装完成后,你需要配置Apache以支持WordPress。这包括创建一个新的虚拟主机配置文件并启用它。
sudo nano /etc/apache2/sites-available/wordpress.conf
在文件中添加以下内容:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName yourdomain.com
DocumentRoot /var/www/html/wordpress
<Directory /var/www/html/wordpress>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log
CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined
</VirtualHost>
将yourdomain.com
替换为你的域名。
sudo a2ensite wordpress.conf
sudo a2dissite 000-default.conf
确保只允许HTTP和HTTPS流量通过防火墙。
sudo ufw allow 'Apache Full'
最后,重启Apache以应用所有更改。
sudo systemctl restart apache2
从WordPress官网下载最新版本的WordPress,然后解压到Apache的默认网站根目录。
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz -C /var/www/html/
确保WordPress文件和目录的权限设置正确。
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
打开浏览器,访问你的服务器IP地址或域名,然后按照WordPress安装向导完成安装。
请注意,以上步骤是基于Ubuntu系统的,如果你使用的是其他Linux发行版,命令可能会有所不同。此外,确保在配置防火墙时只允许必要的端口(如80和443)通过,以保持服务器的安全性。