系统版本:Ubuntu版本 23.04
一.安装前提
1. 确保系统更新
在安装Apache之前,我们需要确保系统已经更新到版本。可以通过以下命令来更新系统:
sudo apt upgrade
2 确保系统没有其他Web服务器
在安装Apache之前,我们需要确保系统上没有其他的Web服务器软件。可以通过以下命令来检查系统上是否已经安装了其他Web服务器:
sudo netstat -tlnp | grep :80
如果输出为空,则表示系统上没有其他Web服务器。
二. 安装Apache
1.使用apt命令安装Apache
sudo apt install apache2
在安装过程中,系统会提示你输入密码以确认安装。
2.启动Apache服务
安装完成后,我们需要启动Apache服务。可以通过以下命令来启动Apache:
sudo systemctl start apache2
3.设置开机自启服务,以便在系统启动时自动启动
sudo systemctl enable apache2
4.检查Apache服务的状态,确保它正在运行
sudo systemctl status apache2
效果图:
5.现在还可以通过访问服务器的IP地址或域名在web浏览器中查看默认的Ubuntu Apache2测试页面。
如果你的Ubuntu系统有防火墙(如UFW),确保允许HTTP和HTTPS流量:
sudo ufw allow 'Apache Full'
sudo ufw enable # 如果防火墙之前没有启用
6.关闭Apache服务(如果需要的话)
如果需要关闭Apache服务。可以通过以下命令来关闭Apache:
sudo systemctl stop apache2
关闭后,可以通过上面第四步命令检查当前Apache的运行状态。
三.相关文章
buntu为什么每次用apt安装软件前都要更新(apt upgrade)一下?