当前位置: 首页 > 编程文章 >

ThinkPHP Apache伪静态配置重启失败解决:80端口占用排查

ThinkPHP Apache伪静态配置重启失败解决:80端口占用排查

作者:顾安时间:2025-12-19 17:03:34浏览:723

在Apache环境下配置ThinkPHP伪静态后,执行restart命令导致服务启动失败。通过systemctl status和journalctl -xe日志分析,发现错误源于80端口被重复监听。检查配置文件发现httpd-vhosts.conf与httpd.conf中均存在Listen 80指令,注释其中一处即可恢复正常。

本文目录展开

Apache重启失败现象与初步排查

概要说明

thinkphp 在Apache上配置启用伪静态,重启Apache1 restart 竟然失败了,报错

系统提示Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details。

根据错误提示,首先查看服务状态以获取更多信息。

运行命令systemctl status httpd.service来检查当前服务运行状况。


[root@cloud1 bin]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
  Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
  Active: failed (Result: exit-code) since 五 2026-08-26 11:13:09 CST; 6min ago
   Docs: man:httpd(8)
      man:apachectl(8)
 Process: 9915 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
 Process: 9913 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 9913 (code=exited, status=1/FAILURE)
 
8月 26 11:13:09 cloud1.localdomain httpd[9913]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
8月 26 11:13:09 cloud1.localdomain httpd[9913]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
8月 26 11:13:09 cloud1.localdomain httpd[9913]: no listening sockets available, shutting down
8月 26 11:13:09 cloud1.localdomain httpd[9913]: AH00015: Unable to open logs
8月 26 11:13:09 cloud1.localdomain systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
8月 26 11:13:09 cloud1.localdomain kill[9915]: kill: cannot find process ""
8月 26 11:13:09 cloud1.localdomain systemd[1]: httpd.service: control process exited, code=exited status=1
8月 26 11:13:09 cloud1.localdomain systemd[1]: Failed to start The Apache HTTP Server.
8月 26 11:13:09 cloud1.localdomain systemd[1]: Unit httpd.service entered failed state.
8月 26 11:13:09 cloud1.localdomain systemd[1]: httpd.service failed.

从输出结果中可以观察到,80端口已被其他进程占用,导致Apache无法绑定该端口。

接着执行journalctl -xe命令查看详细日志记录。


[root@cloud1 bin]# journalctl -xe
--
-- Unit session-9830.scope has finished starting up.
--
-- The start-up result is done.
8月 26 11:01:01 cloud1.localdomain systemd[1]: Starting Session 9830 of user root.
-- Subject: Unit session-9830.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-9830.scope has begun starting up.
8月 26 11:01:01 cloud1.localdomain CROND[9744]: (root) CMD (run-parts /etc/cron.hourly)
8月 26 11:01:01 cloud1.localdomain run-parts(/etc/cron.hourly)[9747]: starting 0anacron
8月 26 11:01:01 cloud1.localdomain run-parts(/etc/cron.hourly)[9753]: finished 0anacron
8月 26 11:01:01 cloud1.localdomain run-parts(/etc/cron.hourly)[9755]: starting 0yum-hourly.cron
8月 26 11:01:01 cloud1.localdomain run-parts(/etc/cron.hourly)[9759]: finished 0yum-hourly.cron
8月 26 11:10:01 cloud1.localdomain systemd[1]: Started Session 9831 of user root.
-- Subject: Unit session-9831.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-9831.scope has finished starting up.
--
-- The start-up result is done.
8月 26 11:10:01 cloud1.localdomain systemd[1]: Starting Session 9831 of user root.
-- Subject: Unit session-9831.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-9831.scope has begun starting up.
8月 26 11:10:01 cloud1.localdomain CROND[9870]: (root) CMD (/usr/lib64/sa/sa1 1 1)
8月 26 11:13:09 cloud1.localdomain polkitd[1171]: Registered Authentication Agent for unix-process:9908:450142261 (system bus name :1.19686 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object p
8月 26 11:13:09 cloud1.localdomain systemd[1]: Starting The Apache HTTP Server...
-- Subject: Unit httpd.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit httpd.service has begun starting up.
8月 26 11:13:09 cloud1.localdomain httpd[9913]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
8月 26 11:13:09 cloud1.localdomain httpd[9913]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
8月 26 11:13:09 cloud1.localdomain httpd[9913]: no listening sockets available, shutting down
8月 26 11:13:09 cloud1.localdomain httpd[9913]: AH00015: Unable to open logs
8月 26 11:13:09 cloud1.localdomain systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
8月 26 11:13:09 cloud1.localdomain kill[9915]: kill: cannot find process ""
8月 26 11:13:09 cloud1.localdomain systemd[1]: httpd.service: control process exited, code=exited status=1
8月 26 11:13:09 cloud1.localdomain systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit httpd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit httpd.service has failed.
--
-- The result is failed.
8月 26 11:13:09 cloud1.localdomain systemd[1]: Unit httpd.service entered failed state.
8月 26 11:13:09 cloud1.localdomain systemd[1]: httpd.service failed.
8月 26 11:13:09 cloud1.localdomain polkitd[1171]: Unregistered Authentication Agent for unix-process:9908:450142261 (system bus name :1.19686, object path /org/freedesktop/PolicyKit1/Authenticatio
 

上述操作用于调取系统日志,辅助定位具体故障原因。

进一步检查Apache配置文件中的httpd-vhosts.conf,发现Listen 80指令出现了两次,分别位于httpd-vhosts.conf和httpd.conf文件中。

在虚拟机环境中,将其中一个Listen 80行添加#号进行注释,成功解决了冲突问题。

备注:关于apache\Apache\conf目录下extra和original文件夹的作用说明。

extra目录代表额外扩展配置区域。

original目录表示源目录文件备份区。

original文件夹存放配置文件的原始备份,实际生效的配置需修改conf目录下的httpd.conf文件以及extra目录中的扩展配置。

感谢阅读,希望本文能帮助大家解决问题,谢谢大家对本站的支持!

上一篇
PHP实现二维数组分页的两种方法解析

本文介绍在PHP中对二维数组进行分页处理的两种常见实现思路。第一种方法基于array_slice函数,通过计算偏移量截取指定长度的子数组;第二种方法则利用数组指针与循环遍历的方式,手动定位并提取当前页所需的数据片段。这两种方案均能有效解决非数据库场景下的数据分块展示问题。

下一篇
PHP fread 函数使用详解与常见陷阱规避

本文介绍 PHP fread() 函数的行为机制,包括其停止读取的条件(如达到长度、EOF 或网络包可用)。重点解析使用 fread 时遇到的三大常见问题:超出内存限制导致的大文件读取错误、PHP7.0 以下版本缺乏自动编码识别导致的乱码风险,以及 Windows 平台文本模式下末尾特殊字节引发的多余空字符问题。

相关文章

更多
解决80端口被占用导致Apache启动失败的方法

当Apache服务器因80端口被其他程序占用而无法启动时,可通过命令行工具定位冲突进程。在Windows系统中,使用netstat -aon命令查看端口占用情况并获取对应PID,随后在任务管理器中结束该进程即可释放端口,使Apache恢复正常启动。

2025.09.28 720
ThinkPHP6.0 URL重写去除index.php的正确配置方法

本文解决ThinkPHP6.0在Apache环境下通过URL重写隐藏入口文件index.php时遇到的配置错误。重点指出官网示例中RewriteRule末尾缺少PATH_INFO环境变量导致的404问题,并提供正确的.htaccess配置代码及Apache AllowOverride设置步骤。

2025.03.13 610
Apache配置去除ThinkPHP URL中的index.php

本文介绍如何在Apache服务器环境下,通过修改配置文件和添加.htaccess规则,将ThinkPHP应用URL中的index.php移除。主要步骤包括启用mod_rewrite模块、设置AllowOverride为All、配置项目URL_MODEL为2,以及编写正确的RewriteRule规则。此方法可实现更简洁的URL结构,提升用户体验。

2026.07.25 603
XAMPP安装时Apache 80端口被占用的排查与解决

XAMPP集成环境在安装时若遇到Apache无法启动且提示80端口被占用,通常是因为系统其他服务正在使用该端口。通过命令行工具定位占用进程后,发现SQL Server Reporting Services等后台服务是常见原因。只需在Windows服务管理器中停止这些冲突服务,即可重新成功安装并运行XAMPP。

2026.03.13 432
Apache 启动失败排查:解决 80 端口被 System 占用

安装 MongoDB 后 Apache2a 服务启动报错,错误码为 1。通过查看 httpd.exe 日志发现因 80 端口被占用导致绑定失败。使用 netstat -ano|findstr 80 命令查询到占用 PID 为 4,对应 System 进程。经查该进程通常由 SQL Server Reporting Services (MSSQLSERVER) 服务引起,禁用该服务后 Apache 成功启动。

2026.09.27 387
Apache开启.htaccess及使用方法详解

本文介绍如何在本地Apache环境中启用.htaccess文件,主要涉及修改httpd.conf中的AllowOverride参数。同时详细解析.htaccess的多种实用功能,包括自定义错误页面、目录密码保护、IP访问限制、URL自动转向、默认首页设置以及防止图片盗链等配置方法,并分析了使用.htaccess对服务器性能和安全性的潜在影响。

2026.05.09 1,005

专题推荐

更多
PHP 类与对象定义及继承

先看类声明、对象实例与属性访问。理解对象的创建和销毁后,再读继承、方法重载和关键字对照。已有代码遇到继承行为差异时,可进一步查看 final 方法与反射实例。

PHP 定时任务配置与运行

先确定任务运行间隔以及是否允许重叠。固定时间触发先看 Cron 案例,框架内和常驻服务再读对应示例。

Yii2 队列配置与常驻运行

先用一个最小任务跑通入队和消费,再检查 Web 与 Console 是否加载了相同的队列配置。确认命令能手动运行后再配置 Supervisor,最后验证进程重启时的处理情况。

PHP Session 过期时间设置方法

浏览器关闭、服务端回收和业务规定的闲置超时,可能在不同时间发生。对照配置项与应用层时间戳的做法,检查会话何时仍可读、何时应要求重新登录。

PHP URL 编码和解码方法

URL 路径片段和查询参数对空格的处理方式不同。先比较 urlencode 与 rawurlencode,再沿解码过程核对中文、加号和百分号,检查地址是否被重复编码或提前解码。

在线工具箱

更多
键码查询
键码查询

按下键盘按键时查看浏览器记录的键名和事件信息。

.env 配置检查
.env 配置检查

本地检查 .env 键值语法、引号、重复键及空值,预览解析结果,辅助排查 PHP 和 Laravel 环境配置。

进制转换
进制转换

转换二进制、十进制、十六进制等数值表示,辅助程序调试与进制学习。

HTML 标签安全清理
HTML 标签安全清理

清理 HTML 片段中的标签或危险内容,辅助整理待展示的文本。

文件 Base64 转换
文件 Base64 转换

把文件转为 Base64 文本,也可将编码内容还原为文件,方便接口传输与调试。