MacBook Air M4 — Complete Installation & Configuration
Apple Silicon M4 Macs run on ARM64 architecture. Homebrew installs to /opt/homebrew on Apple Silicon (vs /usr/local on Intel). Make sure you are using a native ARM terminal — do not use Rosetta.
macOS ships with a legacy Apache, but it's outdated and unsupported. We'll use Homebrew to install a modern, maintained version.
xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
# Verify Homebrew works
brew --version
Homebrew's Apache formula is called httpd. Before installing, disable the built-in macOS Apache if it's running.
# Stop the built-in apache if running
sudo apachectl stop
# Disable it from auto-starting
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
brew install httpd
httpd -v
# Expected output: Server version: Apache/2.4.x (Homebrew)
Apache installs to /opt/homebrew/opt/httpd/. Config files live at /opt/homebrew/etc/httpd/. Document root defaults to /opt/homebrew/var/www.
Use brew services to manage Apache as a background service that auto-starts on login.
# Start Apache (and auto-start on login)
brew services start httpd
# Stop Apache
brew services stop httpd
# Restart Apache
brew services restart httpd
# Check status
brew services info httpd
# Start
/opt/homebrew/bin/apachectl start
# Stop
/opt/homebrew/bin/apachectl stop
# Graceful restart (applies config changes)
/opt/homebrew/bin/apachectl graceful
# Test config for syntax errors before restarting
/opt/homebrew/bin/apachectl configtest
After starting, open your browser and navigate to:
http://localhost:8080
# You should see: "It works!"
Homebrew's Apache defaults to port 8080 (not 80) to avoid requiring root privileges. You can change this in httpd.conf.
The main config file is /opt/homebrew/etc/httpd/httpd.conf. Open it in your editor:
# Open with nano
nano /opt/homebrew/etc/httpd/httpd.conf
# Or open with VS Code
code /opt/homebrew/etc/httpd/httpd.conf
Find and replace the Listen directive in httpd.conf:
# Find this line:
Listen 8080
# Change to:
Listen 80
Ports below 1024 require root. If using port 80, start Apache with sudo /opt/homebrew/bin/apachectl start or configure a port forwarding rule instead.
Your web files go in the Document Root. To change it to your home folder's Sites directory:
# Find and replace these two lines (use your username):
DocumentRoot "/Users/YOUR_USERNAME/Sites"
<Directory "/Users/YOUR_USERNAME/Sites">
mkdir -p ~/Sites
echo "<h1>Hello from Apache on M4!</h1>" > ~/Sites/index.html
Find the <Directory> block for your root and ensure it allows access:
<Directory "/Users/YOUR_USERNAME/Sites">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Find the User and Group lines and set them to your username:
User YOUR_USERNAME
Group staff
In httpd.conf, uncomment this line (remove the #):
# Before:
#LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
# After (remove the #):
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
# Always test config before restarting
/opt/homebrew/bin/apachectl configtest
# If "Syntax OK", restart
brew services restart httpd
Virtual Hosts let you run multiple sites on one machine using local domain names like myproject.test.
Uncomment this line in httpd.conf:
# Uncomment this line (remove the #):
Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
nano /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
# Default catch-all (keep this first)
<VirtualHost *:8080>
DocumentRoot "/opt/homebrew/var/www"
ServerName localhost
</VirtualHost>
# Your custom local site
<VirtualHost *:8080>
DocumentRoot "/Users/YOUR_USERNAME/Sites/myproject"
ServerName myproject.test
ErrorLog "/opt/homebrew/var/log/httpd/myproject-error.log"
CustomLog "/opt/homebrew/var/log/httpd/myproject-access.log" combined
<Directory "/Users/YOUR_USERNAME/Sites/myproject">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Map your local domain name to 127.0.0.1:
sudo nano /etc/hosts
# Add this line at the end:
127.0.0.1 myproject.test
Now visit http://myproject.test:8080 in your browser.
Install PHP via Homebrew and wire it into Apache using the mod_php module (or FastCGI).
brew install php
# Verify
php -v
Add this line to the LoadModule section of httpd.conf:
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so
Also in httpd.conf, find the <IfModule mime_module> block and add:
<IfModule mime_module>
# ...existing lines...
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>
Find the DirectoryIndex line and add index.php:
DirectoryIndex index.php index.html
echo "<?php phpinfo(); ?>" > /opt/homebrew/var/www/info.php
# Visit http://localhost:8080/info.php
brew services restart httpd
If you need Apache accessible on your local network (e.g., testing from another device), ensure macOS firewall allows it.
# Add httpd as an allowed application
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add /opt/homebrew/opt/httpd/bin/httpd
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --unblockapp /opt/homebrew/opt/httpd/bin/httpd
# Check if port 8080 is in use
lsof -i :8080
# Find your local IP address
ipconfig getifaddr en0
Other devices on your network can reach your server at http://YOUR_LOCAL_IP:8080 — handy for mobile testing.
# Watch error log in real time
tail -f /opt/homebrew/var/log/httpd/error_log
# View access log
tail -f /opt/homebrew/var/log/httpd/access_log
# Check syntax errors in config
/opt/homebrew/bin/apachectl configtest
# Check if httpd process is running
ps aux | grep httpd
# Force-stop all httpd processes
sudo pkill -9 httpd
# Reinstall httpd cleanly
brew reinstall httpd
# Check Homebrew for issues
brew doctor
# Main config file
/opt/homebrew/etc/httpd/httpd.conf
# Virtual hosts config
/opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
# Default document root
/opt/homebrew/var/www/
# Error log
/opt/homebrew/var/log/httpd/error_log
# Access log
/opt/homebrew/var/log/httpd/access_log
# Apache binary
/opt/homebrew/bin/apachectl
# Apache modules directory
/opt/homebrew/lib/httpd/modules/
You're all set! Visit http://localhost:8080 to confirm Apache is running. Use brew services list to check service status at any time.