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

84,755

Solution 1

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.

Solution 2

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>
Share:
84,755

Related videos on Youtube

Gameshadow
Author by

Gameshadow

Updated on September 18, 2022

Comments

  • Gameshadow
    Gameshadow over 1 year

    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?

    • Giacomo1968
      Giacomo1968 over 8 years
      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?
  • Gameshadow
    Gameshadow over 8 years
    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.
  • Giacomo1968
    Giacomo1968 over 8 years
    @Gameshadow Sounds good! But remember to run the launchctl unload to make sure Apache doesn’t startup again on reboot.