1. 安装Apache:

    • 在Ubuntu/Debian上:sudo apt-get install apache2

    • 在CentOS/RHEL上:sudo yum install httpd

  2. 启动Apache服务:

    • 在Ubuntu/Debian上:sudo systemctl start apache2

    • 在CentOS/RHEL上:sudo systemctl start httpd

  3. 设置Apache开机自启:

    • 在Ubuntu/Debian上:sudo systemctl enable apache2

    • 在CentOS/RHEL上:sudo systemctl enable httpd

  4. 配置端口:

    • 编辑配置文件:sudo nano /etc/apache2/ports.conf(Ubuntu/Debian)或sudo nano /etc/httpd/conf/httpd.conf(CentOS/RHEL)

    • 修改Listen指令后的端口号,例如:Listen 8080

  5. 检查端口占用:

    • 使用命令:sudo netstat -tuln | grep :80(检查80端口)

    • 如果端口被占用,可以更改Apache的监听端口或停止占用端口的服务。

  6. 重启Apache服务:

    • 在Ubuntu/Debian上:sudo systemctl restart apache2

    • 在CentOS/RHEL上:sudo systemctl restart httpd

本篇文章内容来源于:apache安装与配置端口占用