Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Killing an unknown self restarting server on port 80 Mac OSX

I have a server running on port 80, but I do not know what it is or where it came from. When I run

sudo lsof -i :80 | grep LISTEN

I get

httpd      80    root    5u  IPv6 0x91f5a9de62859cfd      0t0  TCP *:http (LISTEN)
httpd     694    _www    5u  IPv6 0x91f5a9de62859cfd      0t0  TCP *:http (LISTEN)

I have tried to enter get the process name using the PID, but all I ever get in return is "httpd" or "FOREGROUND".

When I kill the PID, the process simply restarts with a new PID. I assume I will have to stop it at launch.

How can I stop this server from running at startup?

If it helps any, I am trying to free up port 80 to use the apache server on MAMP.

like image 985
Stephen Mather Avatar asked Sep 03 '16 17:09

Stephen Mather


Video Answer


4 Answers

This is just a guess, but it might be the built-in version of apache, being launched (& restarted) by launchd (OS X's daemon manager). It's disabled by default, but might've gotten enabled somehow. You can try disabling it with:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

If that doesn't do it (it'll say something like "Could not find specified service"), you can check to see if it's some other launch daemon item by looking for the PID of the master process (the one running as root, not _www):

sudo launchctl list | grep <masterPID>

That won't necessarily tell you exactly what's going on, but might point you in the right direction.

like image 172
Gordon Davisson Avatar answered Nov 15 '22 18:11

Gordon Davisson


Like Gordon suggested, that's the built-in version of the Apache web server.

You can stop it with

sudo apachectl stop

btw, the configuration for this webserver can be found in the /etc/apache2/httpd.conf directory.

like image 37
P.J.Meisch Avatar answered Nov 15 '22 17:11

P.J.Meisch


This happens to me a lot. As @Gordon Davisson explains it is most likely the launchdeamon process conflicting with the service you have set up. Definitely stop the apachetl server.

sudo apachetl -k stop

Try to find all the httpd process, they should be the last ones

sudo lsof -i :80 // without grep

Then get the first process (most likely in the 1000s) should also be the lowest one.

sudo kill <firstHttpdPID>

This should kill ALL the processes running that httpd instance and then you get simply start back up your server. Must stop it first though or it will continue running again.

like image 20
Douglas Richardson Avatar answered Nov 15 '22 18:11

Douglas Richardson


Mac OSX comes bundled with Apache, however it is deactivated. You might have activated it somehow. In my case, I have previously install XAMPP and configured something in the /etc/apache2/httpd.conf that leads my port localhost:80 to leads to html page with It Works!.

TLDR, the solution is to deactivate the Apache2 server. Go to your terminal, and type this

sudo apachetl -k stop

In my case, it returns the following:

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using Shafies-MacBook-Pro.local. Set the 'ServerName' directive globally to suppress this message
httpd (no pid file) not running

if you typed localhost on your browser, the port 80 is not active anymore and you will not see It Works! anymore.

For context, I have deleted XAMPP long time ago and not aware that my localhost:80 is still active. I am not able redirect dummy domain -- posts.com to my localhost port for my kubernetes YAML config files.

This is my ingress-srv.yaml file:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress-srv
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
  rules:
    - host: posts.com
      http:
        paths:
          - path: /?(.*)
            backend:
              serviceName: client-srv
              servicePort: 3000

and I have tricked the operating system to redirect my posts.com to localhost:80 by adding below line in the hosts file located at /etc/hosts

127.0.0.1 posts.com

by SM

like image 21
Shafie Mukhre Avatar answered Nov 15 '22 17:11

Shafie Mukhre