在 Alibaba Cloud Linux 3.2104 LTS 64位 系统上安装 Apache(即 httpd 服务)非常简单,因为它是基于 RHEL/CentOS 的系统,使用 yum 或 dnf 包管理器。以下是详细的安装步骤:
✅ 步骤 1:更新系统包
sudo yum update -y
✅ 步骤 2:安装 Apache(httpd)
sudo yum install httpd -y
注:Alibaba Cloud Linux 3 默认使用
yum,虽然底层支持dnf,但推荐使用yum保持兼容性。
✅ 步骤 3:启动 Apache 服务并设置开机自启
# 启动 httpd 服务
sudo systemctl start httpd
# 设置开机自启动
sudo systemctl enable httpd
# 查看服务状态
sudo systemctl status httpd
你应该看到输出中显示 active (running)。
✅ 步骤 4:配置防火墙(如启用 firewalld)
如果你的系统启用了 firewalld,需要放行 HTTP(80)端口:
# 添加 HTTP 服务到防火墙
sudo firewall-cmd --permanent --add-service=http
# 重新加载防火墙配置
sudo firewall-cmd --reload
如果你使用的是阿里云 ECS 实例,还需要在阿里云控制台的安全组中放行 80 端口。
✅ 步骤 5:测试 Apache 是否正常工作
- 获取服务器公网 IP(可通过阿里云控制台查看)。
- 在浏览器中访问:
http://<你的公网IP> - 如果看到 "Welcome to Alibaba Cloud Linux" 或 Apache 默认页面,说明安装成功。
你也可以本地测试:
curl http://localhost
✅ (可选)修改默认网页内容
Apache 默认页面路径为:
/var/www/html/
例如,创建一个简单的测试页面:
echo "<h1>Hello from Alibaba Cloud Linux!</h1>" | sudo tee /var/www/html/index.html
刷新浏览器即可看到新内容。
✅ 常用命令总结
| 功能 | 命令 |
|---|---|
| 启动 Apache | sudo systemctl start httpd |
| 停止 Apache | sudo systemctl stop httpd |
| 重启 Apache | sudo systemctl restart httpd |
| 查看状态 | sudo systemctl status httpd |
| 配置文件位置 | /etc/httpd/conf/httpd.conf |
| 网站根目录 | /var/www/html/ |
🔐 安全建议
- 定期更新系统和 Apache。
- 如需使用 HTTPS,建议配合 Let’s Encrypt 安装 SSL 证书(使用
certbot)。 - 避免以 root 运行服务,Apache 默认使用
apache用户运行,确保配置正确。
如有需要,还可以安装 PHP、MySQL 等组件,搭建完整的 LAMP 环境。
✅ 完成!你现在已经在 Alibaba Cloud Linux 3 上成功安装并运行了 Apache 服务器。
ECLOUD博客