'macOS Mojave - httpd process is running, but sudo apachectl stop results in httpd (no pid file) not running

Title pretty much covers it. I have an apache web server taking over localhost. When I visit http://127.0.0.1 I see a white page with "It works!" on it. Default apache stuff.

I take a look at running httpd processes, which shows multiple running

> ps -ef | grep httpd
    0 47867     1   0  8:24AM ??         0:00.18 /usr/sbin/httpd -D FOREGROUND
   70 47871 47867   0  8:24AM ??         0:00.00 /usr/sbin/httpd -D FOREGROUND

This is interferring with another service I want to use for localhost. So I try to kill the local apache only to get the "not running" response.

> sudo apachectl stop
httpd (no pid file) not running

So how do I stop the running apache process?



Solution 1:[1]

I suspect this error has many causes, but here's one I just encountered and the corresponding solution.

You can get this misleading error message if the apache process is owned by root and you execute the apachectl command as a different user.

If you have root access on the machine, you can do sudo apachectl stop and that should work. I'm not aware of a way to stop it if you don't have root access.

Solution 2:[2]

Try following command in you mac terminal:

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

command2: sudo apachectl -k restart

Then try sudo apachectl start

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 weissj
Solution 2 Al Shahirar