Amazon.co.uk Widgets

Log in

X
Running Homebrew PHP on Apache on macOS Tahoe

This guide shows how to configure Apache installed via Homebrew on macOS to serve PHP files. It covers prerequisites, configuration changes, and simple tests to confirm PHP is working correctly.

Prerequisites

  • macOS with Homebrew installed
  • Homebrew httpd service running
  • PHP installed via Homebrew (brew install php)
  • Basic familiarity editing configuration files

Steps

  1. Locate your Apache configuration file:
    The main config is usually at /opt/homebrew/etc/httpd/httpd.conf.
  2. Include PHP settings:
    Add the following line near the bottom of httpd.conf:
    # PHP settings
    Include /opt/homebrew/etc/httpd/extra/httpd-php.conf
  3. Create or edit httpd-php.conf:
    Add these lines:
    # PHP
    LoadModule php_module /opt/homebrew/lib/httpd/modules/libphp.so
    
    <IfModule php_module>
      <FilesMatch \.php$>
        SetHandler application/x-httpd-php
      </FilesMatch>
    
      <IfModule dir_module>
        DirectoryIndex index.html index.php
      </IfModule>
    </IfModule>
  4. Restart Apache:
    Run:
    brew services restart httpd
  5. Test PHP:
    In your Apache document root (e.g. /opt/homebrew/var/www), create a file called info.php:
    <?php
    phpinfo();
    ?>
    Then visit http://localhost:8080/info.php (or your configured port).

Verification

If PHP is configured correctly, you’ll see the PHP information page showing version details, loaded modules, and configuration paths.

See Running Homebrew Apache with Let's Encrypt SSL on macOS Tahoe and Running Homebrew MySQL or MariaDB on macOS Tahoe.

Homebrew Logo: Vítor Galvão (creator); MikeMcQuaid, Synoli (committers), BSD, via Wikimedia Commons