18

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?

0

2 Answers 2

37

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.

0
7

sudo apachectl start to make sure it is running

go to http://localhost:80 to ensure you see "It Works!" or something comes up to confirm it is running.

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

cat /private/var/db/com.apple.xpc.launchd/disabled.plist should produce output similar to the following to show that httpd has been disabled from autostarting.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.ftpd</key>
    <true/>
    <key>com.apple.mdmclient.daemon.runatboot</key>
    <true/>
    <key>org.apache.httpd</key>
    <true/>
</dict>
</plist>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .