How to Install Apache on macOS via Homebrew

Post Date: October 25, 2018
Last Updated: September 30, 2026

Introduction

Apache HTTP Server, commonly called Apache or httpd, is a widely used open-source web server for hosting websites and web applications.

On macOS, Apache can be installed and managed using Homebrew, a package manager for macOS. Homebrew provides a maintained httpd formula and supports both Apple Silicon and Intel Mac systems.


Prerequisites

Before starting, make sure you have:

  • A supported macOS system
  • Terminal access
  • Homebrew installed
  • A user account with permission to install Homebrew packages

You can verify that Homebrew is installed:

brew --version

If Homebrew is not installed, follow the official Homebrew installation documentation.

You can also check the Homebrew installation prefix:

brew --prefix

Typical locations are:

/opt/homebrew

for Apple Silicon Macs and:

/usr/local

for Intel Macs.


Implementation

1. Check for an Existing Apache Installation

Before installing another Apache instance, check whether an existing Apache process is running:

ps aux | grep '[h]ttpd'

You can also check whether ports commonly used by Apache are already occupied:

lsof -nP -iTCP:80 -sTCP:LISTEN

and:

lsof -nP -iTCP:8080 -sTCP:LISTEN

Important: Do not automatically unload or remove macOS’s system Apache just because you are installing the Homebrew version. The Homebrew installation uses its own configuration, binaries, document root, and service management.


2. Install Apache Using Homebrew

Install the Apache HTTP Server package:

brew install httpd

Homebrew currently provides Apache through the httpd formula. The current formula is Apache HTTP Server 2.4.68 as of September 2026.

The Apache HTTP Server project also lists 2.4.68 as its current stable release.

After installation, verify the package:

brew info httpd

Check the installed Apache version:

$(brew --prefix)/opt/httpd/bin/httpd -v

You should see output similar to:

Server version: Apache/2.4.x

The exact version may change as Homebrew updates the formula.


3. Identify the Homebrew Apache Paths

Homebrew installs Apache separately from the macOS system installation.

Find the Homebrew prefix:

brew --prefix

Find the Apache installation:

brew --prefix httpd

For example:

/opt/homebrew/opt/httpd

on Apple Silicon.

The main configuration file is located at:

$(brew --prefix)/etc/httpd/httpd.conf

You can confirm the configuration path with:

$(brew --prefix)/opt/httpd/bin/httpd -V

Look for the SERVER_CONFIG_FILE and HTTPD_ROOT values in the output.


4. Understand the Default Homebrew Apache Port

Unlike many traditional Apache installations, Homebrew configures Apache to listen on port 8080 by default.

The default Homebrew configuration uses:

8080

for HTTP and:

8443

for HTTPS. This allows Apache to run without requiring root privileges to bind to privileged ports such as 80 and 443.

Check the configured HTTP port:

grep -n "^Listen" "$(brew --prefix)/etc/httpd/httpd.conf"

You should see something similar to:

Listen 8080

5. Start Apache Manually

You can start Apache using the Homebrew-installed binary:

"$(brew --prefix)/opt/httpd/bin/httpd"

Alternatively, use:

apachectl start

Because multiple Apache installations can exist on macOS, it is safer to verify which executable is being used:

which apachectl

You can also check:

apachectl -V

6. Start Apache Using Homebrew Services

For development systems, Homebrew services provide a convenient way to manage Apache as a background service.

Start Apache:

brew services start httpd

Homebrew’s current httpd formula officially provides this service command.

Check the service:

brew services list

You should see httpd listed.

Homebrew uses macOS’s service-management mechanism through launchctl for services.


7. Verify That Apache Is Running

Check the running Apache processes:

ps aux | grep '[h]ttpd'

Check the listening port:

lsof -nP -iTCP:8080 -sTCP:LISTEN

You can also use:

sudo lsof -nP -iTCP:8080 -sTCP:LISTEN

If Apache is running correctly, the output should show an Apache/httpd process listening on port 8080.


8. Test Apache in a Browser

Because Homebrew configures Apache to listen on port 8080 by default, open:

http://localhost:8080

You can also test from Terminal:

curl -I http://localhost:8080

A successful response should return an HTTP status such as:

HTTP/1.1 200 OK

The exact response headers may vary depending on the Apache configuration.


9. Locate the Apache Document Root

The Homebrew httpd formula uses:

$HOMEBREW_PREFIX/var/www

as its default document root.

Find the Homebrew prefix:

brew --prefix

For example, on Apple Silicon:

/opt/homebrew

The document root would therefore be:

/opt/homebrew/var/www

Check it:

ls -la "$(brew --prefix)/var/www"

10. Create a Test Web Page

Create a simple HTML file:

echo '<h1>Apache is running on macOS</h1>' > "$(brew --prefix)/var/www/index.html"

Restart Apache:

brew services restart httpd

Test it:

curl http://localhost:8080

Or open:

http://localhost:8080

in your browser.


11. Stop Apache

To stop the Homebrew Apache service:

brew services stop httpd

You can verify the service status:

brew services list

You can also stop Apache using:

apachectl stop

Use the Homebrew service commands when Apache was started through brew services.


12. Restart Apache

After changing Apache configuration, first validate the configuration:

apachectl -t

A successful validation should return:

Syntax OK

Then restart Apache:

brew services restart httpd

Alternatively:

apachectl -k restart

Best practice: Always run apachectl -t before restarting Apache after configuration changes.


13. Change Apache Configuration

The primary Homebrew Apache configuration file is:

"$(brew --prefix)/etc/httpd/httpd.conf"

Open it with a text editor:

nano "$(brew --prefix)/etc/httpd/httpd.conf"

Before making changes, create a backup:

cp "$(brew --prefix)/etc/httpd/httpd.conf" \
   "$(brew --prefix)/etc/httpd/httpd.conf.backup"

After making changes:

apachectl -t

If the output is:

Syntax OK

restart Apache:

brew services restart httpd

14. Change Apache From Port 8080 to Port 80

Homebrew intentionally uses port 8080 by default so Apache can run without privileged access.

If you specifically need Apache to listen on port 80, edit:

nano "$(brew --prefix)/etc/httpd/httpd.conf"

Find:

Listen 8080

Change it to:

Listen 80

Then test the configuration:

apachectl -t

If the configuration is valid, restart Apache:

brew services restart httpd

Check the port:

sudo lsof -nP -iTCP:80 -sTCP:LISTEN

Note: Port 80 is a privileged port on macOS. Running Apache on port 8080 is generally simpler for local development and does not require privileged port binding.


15. Configure a Virtual Host

For local development, you may want to host multiple projects.

First make sure the virtual-host configuration is enabled in httpd.conf.

For example:

Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf

On Intel Macs, the Homebrew prefix may instead be:

Include /usr/local/etc/httpd/extra/httpd-vhosts.conf

A more portable approach is to use the actual Homebrew prefix:

brew --prefix

Edit the virtual-host configuration:

nano "$(brew --prefix)/etc/httpd/extra/httpd-vhosts.conf"

Example:

<VirtualHost *:8080>
    ServerName myproject.local
    DocumentRoot "/path/to/myproject"

    <Directory "/path/to/myproject">
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog "/path/to/myproject/error.log"
    CustomLog "/path/to/myproject/access.log" common
</VirtualHost>

Test the configuration:

apachectl -t

Then restart:

brew services restart httpd

16. Configure a Local Domain

If you want to access the project using:

http://myproject.local:8080

add an entry to /etc/hosts:

sudo nano /etc/hosts

Add:

127.0.0.1 myproject.local

Then test:

curl -I http://myproject.local:8080

This setup is useful for local web development when testing multiple websites or applications.


17. Check Apache Logs

Apache logs are useful when troubleshooting configuration or application problems.

Check the configured log paths:

grep -n "ErrorLog\|CustomLog" "$(brew --prefix)/etc/httpd/httpd.conf"

Depending on the Homebrew configuration, logs are stored under the Homebrew Apache directories.

You can also locate Apache log files with:

find "$(brew --prefix)/var" -iname "*.log" | grep httpd

For virtual hosts, define separate logs when appropriate:

ErrorLog "/path/to/project/error.log"
CustomLog "/path/to/project/access.log" common

18. Troubleshooting

Apache fails to start

First test the configuration:

apachectl -t

Then check the service:

brew services list

Check whether another application is using port 8080:

lsof -nP -iTCP:8080 -sTCP:LISTEN

Port 8080 is already in use

Find the process:

lsof -nP -iTCP:8080 -sTCP:LISTEN

If another application is using the port, either stop that application or change Apache’s listening port.


Apache returns “403 Forbidden”

Check the <Directory> configuration.

For example:

<Directory "/path/to/myproject">
    AllowOverride All
    Require all granted
</Directory>

Then validate and restart:

apachectl -t
brew services restart httpd

Also verify that the macOS user running Apache can access the document-root directory.


Apache returns “404 Not Found”

Check:

grep -n "DocumentRoot" "$(brew --prefix)/etc/httpd/httpd.conf"

Verify that the requested file exists:

ls -la "$(brew --prefix)/var/www"

For virtual hosts, also check the DocumentRoot specified in the virtual-host configuration.


Apache configuration changes do not take effect

First validate:

apachectl -t

Then restart:

brew services restart httpd

Confirm that the correct Apache process is running:

ps aux | grep '[h]ttpd'

19. Useful Apache and Homebrew Commands

PurposeCommand
Install Apachebrew install httpd
Show Apache package informationbrew info httpd
Show Homebrew prefixbrew --prefix
Show Apache prefixbrew --prefix httpd
Start Apache servicebrew services start httpd
Stop Apache servicebrew services stop httpd
Restart Apache servicebrew services restart httpd
Check Homebrew servicesbrew services list
Test Apache configurationapachectl -t
Show Apache versionapachectl -v
Show Apache build/configurationapachectl -V
Check port 8080lsof -nP -iTCP:8080 -sTCP:LISTEN
Test HTTPcurl -I http://localhost:8080

20. Security and Best Practices

Although this guide focuses on local macOS development, basic security practices still apply.

Keep Apache updated

Homebrew provides updates for the httpd formula. Regularly check:

brew update
brew outdated

Then update when appropriate:

brew upgrade httpd

Do not expose development servers unnecessarily

If Apache is being used only for local development, avoid exposing it to external networks unless there is a specific requirement.

Validate configuration before restarting

Always run:

apachectl -t

before restarting Apache after configuration changes.

Use separate virtual hosts

For multiple local projects, use virtual hosts rather than placing unrelated applications into one document root.

Protect sensitive files

Do not place:

  • .env files
  • Database backups
  • Private keys
  • Application secrets
  • Configuration backups

inside a publicly accessible document root.

Use HTTPS when required

For applications that need HTTPS-specific testing, configure TLS using Apache’s SSL configuration rather than exposing sensitive applications over plain HTTP.


Conclusion

Installing Apache on macOS using Homebrew is straightforward and provides a convenient environment for local web development.

The basic workflow is:

brew install httpd
brew services start httpd
apachectl -t
curl -I http://localhost:8080

Homebrew’s Apache configuration uses port 8080 for HTTP and 8443 for HTTPS by default, allowing the service to run without requiring privileged ports.

For development environments, you can further configure:

  • Custom document roots
  • Virtual hosts
  • Local domains
  • Apache modules
  • PHP integration
  • HTTPS
  • Application-specific logging

Always validate Apache configuration changes before restarting the service and keep the Homebrew Apache package updated.


FAQ

Does macOS already include Apache?

Some macOS versions have included Apache components, but this guide installs Apache separately through Homebrew. You do not need to remove the system components simply to install the Homebrew version.

What command installs Apache using Homebrew?

brew install httpd

What port does Homebrew Apache use by default?

Homebrew’s current httpd formula configures Apache to use 8080 for HTTP and 8443 for HTTPS by default.

How do I start Apache automatically?

Use:

brew services start httpd

Homebrew services integrates with macOS’s service manager.

How do I test the Apache configuration?

Run:

apachectl -t

A valid configuration returns:

Syntax OK

Where is the Homebrew Apache configuration?

Use:

$(brew --prefix)/etc/httpd/httpd.conf

Where is the default document root?

Homebrew’s current httpd formula uses:

$HOMEBREW_PREFIX/var/www

as the default document root.

Can I change Apache to port 80?

Yes, but port 80 is privileged. For local development, keeping Apache on port 8080 is generally simpler.


Related Articles


Looking for Apache Support

Need assistance with Apache installation, configuration, troubleshooting, or server optimisation? Our team is happy to help with your web server and infrastructure requirements. Please reach out to our team here.

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Comment

Scroll to Top