How to Install Apache HTTP Server using HomeBrew on MacOS


How to Install Apache HTTP Server on MacOS – TecAdmin

A much better description is here from the folks at Git-Tower.

We need to install a local apache. This page shows how to install http doing this:

brew install httpd
sudo brew services start httpd

I found apache2 as a module, so I am trying that instead:

brew install apache2
brew services start apache2

Note that using sudo, this fails telling me that Homebrew should not be started as root. So start the apache as normal user.

The Git-Tower folks say it’s better to do this:

brew install httpd php

Note that we’re using the fact that httpd refers to Apache; also note that we’re installing php should you not have it.

Starting, stopping, restarting

brew services start httpd
brew services restart httpd
brew services stop httpd

It has started an apache daemon on port 8080.


The tutorial refers to /usr/local/etc/httpd and /usr/local/var/www, but in fact, at least for me, the configuration is in /opt/homebrew/etc/httpd, and the webroot is in /opt/homebrew/var/www.

Install PHP with Apache

Open /opt/homebrew/etc/httpd/httpd.conf and do these changes:

Listen 8080


Listen 80

Comment in

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

as well as

LoadModule rewrite_module lib/httpd/modules/

Add these lines where the modules are loaded:

LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/
Include /opt/homebrew/etc/httpd/extra/httpd-php.conf

Edit / create a file /opt/homebrew/etc/httpd/extra/httpd-php.conf:

<IfModule php_module>
  <FilesMatch .php$>
    SetHandler application/x-httpd-php

  <IfModule dir_module>
    DirectoryIndex index.html index.php

Virtual Host Setup

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

I’ve e.g. replaced the file by this:

<VirtualHost *:80>
    ServerName koolreport-examples.test
    DocumentRoot /opt/local/www/examples

    <Directory "/opt/local/www/examples">
        Require all granted
        AllowOverride All

<VirtualHost *:80>
    ServerName koolreport.test
    DocumentRoot /opt/local/www/reports

    <Directory "/opt/local/www/reports">
        Require all granted
        AllowOverride All

After having added koolreport.test and koolreport-examples.test to /etc/hosts for

I’m adding koolreport.test as an virtual host; I’ll blog in a separate post about the koolreport installation.

Add a simple phpinfo.php

Create a file /opt/homebrew/var/www/phpinfo.php with this content:

<?php phpinfo();

Restart the Server

brew services restart httpd

Related: [[🧠 Ideaverse/Other/- -|Other]]

Created: 1$=dv.span(dv.current().file.ctime)