How to Disable Default Apache Server on macOS Big Sur to Release Port 80?

approximately 2 minutes of reading

When dockerizing your application under macOS Big Sur, you may encounter a situation where Docker fails to boot specific container that has port 80 assigned on the host machine. This happens because Big Sur comes with Apache 2.4 being preinstalled by default.

This article shows two methods on how to fix the issue.

Semi-Solution

Just use a different port. 🙈 Yes, I'm not kidding. Instead of:

ports:
  - 80:80

in your docker-compose.yml specify other port that is available:

ports:
  - 81:80

and finally run docker-compose up -d.

This will indeed bypass port 80 being taken but you have to admit that this is a naive solution and I am pretty sure you are here for more robust approach.

Proper Solution

We have to do two things:

  1. Stop Apache Server
  2. Prevent it from running again as soon as you restart macOS Big Sur

To stop it, open your favourite terminal application and type:

sudo apachectl stop

This will put Apache HTTP Server down.

We have terminated Apache Server on port 80 but this will last only per OS run. As soon as you restart your operating system, particular process will spawn again welcoming your with the famous "It works!".

To prevent it from auto-starting type:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null

The -w argument is the key to prevent the job from being loaded after macOS restarts.

This is it. I hope you will find this short article useful. Originally I have asked this question on StackOverflow and managed to answer it by myself. If this solution solved your problem, feel free to upvote both the question as well as the answer.

If you want to explore other articles I have tagged with "Docker", check them here.


Words: 288
Published in: macOS
Last Revision: October 25, 2022

Related Articles   📚