今天重裝xampp后,一直無法啟動Apache,提示以下錯誤:
22:36:54 [Apache] Attempting to start Apache app...
22:36:54 [Apache] Status change detected: running
22:36:55 [Apache] Status change detected: stopped
22:36:55 [Apache] Error: Apache shutdown unexpectedly.
22:36:55 [Apache] This may be due to a blocked port, missing dependencies,
22:36:55 [Apache] improper privileges, a crash, or a shutdown by another method.
22:36:55 [Apache] Press the Logs button to view error logs and check
22:36:55 [Apache] the Windows Event Viewer for more clues
22:36:55 [Apache] If you need more help, copy and post this
22:36:55 [Apache] entire log window on the forums
大概意思是端口被占用,查看xampp/apache/conf/httpd.conf文件,里面運用的是80端口,也是瀏覽器默認的80端口。
首先,可以cmd,用netstat -ano來查看端口的占用情況
1. netstat -ano|findstr "80" 查看指定端口80的占用情況
C:\Users\acer>netstat -ano|findstr "80"
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:1026 0.0.0.0:0 LISTENING 800
TCP 192.168.0.102:2113 183.136.138.140:80 TIME_WAIT 0
TCP 192.168.0.102:2114 183.136.138.140:80 ESTABLISHED 732
TCP [::]:80 [::]:0 LISTENING 4
TCP [::]:1026 [::]:0 LISTENING 800
UDP [fe80::ce5:bd05:f942:83da%18]:1900 *:* 1744
UDP [fe80::d8c:1ba:16b4:2a29%17]:1900 *:* 1744
UDP [fe80::7469:be65:7b61:a13b%14]:1900 *:* 1744
依次表示 協議 本地地址 外部地址 狀態 PID
2. 用tasklist命令查看PID對應的進程
C:\Users\acer>tasklist|findstr "732"
TaobaoProtect.exe 732 Console 1 7,956 K
依次表示 映像名稱 PID 會話名 會話# 內存使用
3. 用taskkill命令可以關閉找到的進程,解除端口占用情況
C:\Users\acer>taskkill /f /t /im TaobaoProtect.exe
成功: 已終止 PID 732 (屬於 PID 1880 子進程)的進程。
但是有些情況下,我們有些進程是無法關閉的,或者對應進程較多的時候,關閉也很麻煩。退一步來講,我們可以選擇修改Apache對應的端口,豈不是兩全其美?
我們繼續打開xampp/apache/conf/httpd.conf文件,找到Listen80,將80改為81或者82and so on,保證該端口沒有被占用即可,可以用上面的方法進行檢驗。
我第一次是把所有的80都改為81的,后來發現,只改listen后面這個也可以的~~具體可以去看看Apache的http.conf的詳細解釋,暫時覺得應該都改掉吧。
啊哈,接下來可以重啟Apache了,運氣好的話,發現,還是端口被占用哦。
23:10:29 [Apache] Attempting to start Apache app...
23:10:29 [Apache] Status change detected: running
23:10:30 [Apache] Status change detected: stopped
23:10:30 [Apache] Error: Apache shutdown unexpectedly.
23:10:30 [Apache] This may be due to a blocked port, missing dependencies,
23:10:30 [Apache] improper privileges, a crash, or a shutdown by another method.
23:10:30 [Apache] Press the Logs button to view error logs and check
23:10:30 [Apache] the Windows Event Viewer for more clues
23:10:30 [Apache] If you need more help, copy and post this
23:10:30 [Apache] entire log window on the forums
Google了一下,發現,APACHE 還需要 443 端口,具體可以查看xampp/apache/conf/extra/httpd-ssl.conf文件,里面有個listen443,檢查一下443端口的占用情況,又被占用了,一樣的,將443改為444.
如何找到上面兩個文件,可以采取這樣的方式。如下圖,點擊config,出現的前兩個,便是了~
重啟Apache,OK,搞定,perfect!
23:20:40 [Apache] Attempting to start Apache app...
23:20:41 [Apache] Status change detected: running
點擊admin,或者在瀏覽器輸入localhost或者127.0.0.1,啊哦,
Not Found
HTTP Error 404. The requested resource is not found.
not found?因為瀏覽器的默認端口號為80,而我們不是把端口改為81了嗎?此時可以在localhost后面加上端口號:localhost:81,再回車,就OK了~