How to kill Apache / PHP server running on local h

2019-07-23 03:44发布

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?

3条回答
Bombasti
2楼-- · 2019-07-23 04:12

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.

查看更多
Bombasti
3楼-- · 2019-07-23 04:16
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.

查看更多
三岁会撩人
4楼-- · 2019-07-23 04:36

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.

查看更多
登录 后发表回答