升级Mac OS Sierra后Apache无法访问求助
Hey there, let's work through this Apache issue together—upgrades can definitely mess with our server settings, so we'll go step by step to get it back up and running.
Step 1: Check if Apache is actually running
First, let's confirm Apache's current status. Open up Terminal and run:
sudo apachectl status
- If you see
httpd is not running, that means the service isn't active at all. - If you get an error message instead, note it down—it'll help us narrow things down.
Step 2: Try restarting Apache properly
Sometimes a simple restart fixes post-upgrade glitches. Run these commands in order:
sudo apachectl stop sudo apachectl start
If the start command fails, don't panic—let's check the error logs for details:
cat /var/log/apache2/error_log
Look for lines with [error]—they'll tell you exactly what's broken (like a missing config file, syntax error, or port conflict).
Step 3: Check if Port 80 is being used by another app
macOS upgrades might leave other services (like Node.js servers, Nginx, or even some VPN tools) running on port 80, which Apache needs. To check:
sudo lsof -i :80
This will list all processes using port 80. If you see something other than httpd, you have two options:
- Stop that process (use
kill -9 [PID]where PID is the number in the second column) - Or change Apache's listening port:
- Open
/etc/apache2/httpd.confin a text editor (likesudo nano /etc/apache2/httpd.conf) - Find the line that says
Listen 80and change it toListen 8080 - Save the file (Ctrl+O, then Enter in nano) and restart Apache with
sudo apachectl restart - Now try accessing
localhost:8080instead of justlocalhost
- Open
Step 4: Verify Apache's configuration syntax
Upgrades sometimes reset or corrupt config files. Let's check for syntax errors:
sudo apachectl configtest
If you see Syntax OK, great—configs are fine. If not, the output will tell you which line/file has the problem (for example, a missing semicolon or a commented-out include you need to re-enable).
Step 5: Check permissions on your web root directory
macOS might have changed the ownership of Apache's default web root (/Library/WebServer/Documents/). Let's fix that:
sudo chown -R _www:_www /Library/WebServer/Documents/ sudo chmod -R 755 /Library/WebServer/Documents/
This ensures the Apache user (_www) has the right access to serve files from that folder.
Step 6: Check your firewall settings
Sometimes the macOS firewall blocks Apache's incoming connections. To test:
- Open System Preferences > Security & Privacy > Firewall
- Click the lock icon (enter your password) and then click Firewall Options
- Look for
httpdin the list—make sure it's set to Allow incoming connections - If it's not there, you can add it by clicking the
+button and navigating to/usr/sbin/httpd - Alternatively, temporarily turn off the firewall to see if that fixes the issue (remember to turn it back on later!)
Bonus: Restore custom configurations (if you had any)
If you set up virtual hosts or custom modules before the upgrade, check if their includes are still enabled in httpd.conf:
- Open
/etc/apache2/httpd.confand look for lines like#Include /private/etc/apache2/extra/httpd-vhosts.conf - Remove the
#at the start of the line to re-enable the include, then restart Apache.
Once you've worked through these steps, try accessing localhost (or localhost:8080 if you changed the port) again—it should show the familiar "It Works!" page.
内容的提问来源于stack exchange,提问作者Kat Joy

