问题
I am currently running macOS High Sierra version 10.13.6.
This is what I get when I load localhost:8080 in my browser: Apache / PHP server screenshot
I do not know how this server was started on this port because I have never used these technologies. I do mess around with web development every now and then, but I do not know what I was doing when the server started. I have looked into how to kill the process and so far the closest I have come to ending the server is killing my chrome browser. Some of the things I have tried to find the process running on port 8080:
ps aux | grep 8080
lsof -t -i @localhost:8080
netstat -l -p | grep 8080
lsof -nP -i | grep 8080
There were a few more ones that looked similar that I tried, but I cannot recall all of them. When using the lsof commands, I would usually have to put sudo in front of them for anything to show up. I would sometimes get nothing to come back and sometimes I would get something like this: Terminal output from lsof and ps aux output where the Postgres processes are.
When I got processes back that had a PID associated with them, I would try to kill them with kill -9 <PID>
. Normally I would have to force this with sudo because it gave me a permission denied error (probably not the best practice). When I did this, nothing appeared to happen except other processes appeared when I searched after I killed the initial ones. I also tried to end the processes associated with Postgres from ps aux, but that did not work either. It just seems like whatever processes I am finding are not the correct ones. Does anyone have any suggestions to help me find and kill the process that is hosting the server?
回答1:
From the command line it would be:
sudo /usr/sbin/apachectl stop
To prevent it from starting at the next reboot:
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
Note that I have no idea what else uses apache on your system, so this might break things.
回答2:
You could try with:
ps -e | grep httpd
This will show you apache httpd PIDs. Another way is to install pstree using brew:
brew install pstree
pstree will show running processes as a tree. Then You can find the PPID with the following command:
pstree | grep httpd
Then you can use kill
to terminate the process. I tested both ways on macOS High Sierra.
回答3:
lsof -nP -i | grep "TCP.*:8080.*LISTEN"
Use lsof
to find the process that is waiting for connections ("LISTEN"ing) on port 8080. Use the PID column from that output to kill the process.
来源:https://stackoverflow.com/questions/52209105/how-to-kill-apache-php-server-running-on-local-host-port-8080