Search code examples
phpsessionlocalhostiterm2

How to terminate old session in iTerm2


Maybe a stupid question with an obvious answer, but I don't know the solution. I'm new with the command line and especially Apple and iTerm2.

In iTerm2 I open a new session for my PHP project with php -S localhost:port

Now I accidentally closed this tab once and now I don't know how to terminate that session. When I want to open another project on that port (8000) it says, ofcourse, Failed to listen on 127.0.0.1:8000 (reason: Address already in use)

Can someone help me on how to terminate this session, so I can start another project on this port instead of using 8001, 8002, 8003 etc.

Thanks in advance


Solution

  • I fixed it myself, but since I can't be the only one wondering this, here is my solution:

    Enter this into the terminal:

    lsof -i TCP:8000
    

    It will yield a result that might look something like this:

    renaebair@siren ~/workspace/intridea/newsite (master) 
    → lsof -i TCP:3000
    COMMAND  PID   USER       FD     TYPE     DEVICE     SIZE/OFF    NODE   NAME
    ruby   68780   renaebair   6u    IPv4     0x10898278     0t0      TCP     *:hbci (LISTEN)
    

    Grab the process number (a.k.a. PID) (in this case it was 68780) and then type “kill #{that_pid}”:

    kill 68780 
    

    Then try restarting your server and all should be well!