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
- Locate your Apache configuration file:
The main config is usually at/opt/homebrew/etc/httpd/httpd.conf
. - Include PHP settings:
Add the following line near the bottom ofhttpd.conf
:# PHP settings Include /opt/homebrew/etc/httpd/extra/httpd-php.conf
- 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>
- Restart Apache:
Run:brew services restart httpd
- Test PHP:
In your Apache document root (e.g./opt/homebrew/var/www
), create a file calledinfo.php
:
Then visit<?php phpinfo(); ?>
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