How can I remove Apache2 that I have installed in Mac OS X?

15

3

A while ago I thought that it would be handy to install Apache2 on my MacBook and not go the easy route by just installing MAMP. However now I’ve changed my mind but I can’t simply delete Apache2. I’ve already tried the following:

sudo nano /etc/apache2/httpd.conf

In this file the # symbol was still in front of the PHP5 line, however PHP is still working.

Sometimes the page localhost says: “It Works!” and sometimes it says ERR_CONNECTION_REFUSED.

I’m worried that this will screw up the MAMP installation. I don’t want to reinstall the OS.

I read that the command might help to figure out what’s using the port:

sudo lsof -i:80

This is what it says for me:

How can I remove Apache2?

Gameshadow

Posted 2015-10-14T20:21:19.237

Reputation: 153

Please edit your question: What version of Mac OS X are you on? And how did you install Apache? Do you simply mean you want to stop Apache? – JakeGould – 2015-10-14T20:55:30.563

Answers

26

Your question states you want to remove Apache2 from Mac OS X, but it’s not clear how you installed it or even if you did a custom install. If it’s the Apache that is installed with Mac OS X you don’t want to remove it from the OS, but just deactivate it so it’s not running.

By default Apache comes bundled with Mac OS X but it’s deactivated. So my assumption is you simply started Apache on the system and even set it to come up automatically when the system starts up or reboots. I’m guessing that since your output of sudo lsof -i:80 shows Apache running under the user _www.

Anyway to stop the built-in Apache server in Mac OS X is by using this command:

sudo apachectl -k stop

Then just enter your administrator password. And to prevent Apache from coming up again on if your system reboots/restarts just run this launchctl unload command; you’ll need your administrator password again:

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

When that’s all done, check the output of sudo lsof -i:80 and the built-in Apache web server in Mac OS X should be completely stopped and disabled.

JakeGould

Posted 2015-10-14T20:21:19.237

Reputation: 38 217

Thanks, the atachectl -k stop worked. I think the website is still cached in the browser but I don' t think that's a problem. – Gameshadow – 2015-10-15T12:05:08.470

@Gameshadow Sounds good! But remember to run the launchctl unload to make sure Apache doesn’t startup again on reboot. – JakeGould – 2015-10-15T17:52:30.197