We showed you how to start macOS’s built-in Apache server. Handy for quick tasks, but it can clash with Homebrew PHP, even with SIP disabled!
The Issue: PHP installed via brew is not signed.
The Solution: Install Apache via Homebrew (brew install httpd
) and run it on port 8080. This avoids conflicts with the built-in server and allows seamless integration with your Homebrew PHP installation.
brew install httpd
Modify the default config to suit your needs
nano /opt/homebrew/etc/httpd/httpd.conf
Set the document root
By default, the DocumentRoot is set to:
/opt/homebrew/var/www
Change it to
DocumentRoot "/Users/<your-username>/Sites"
<Directory "/Users/<your-username>/Sites">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Locate the last line of LoadModule Block and paste PHP LoadModule line:
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so
Set the DirectoryIndex to include index.php:
DirectoryIndex index.php index.html
Set the DirectoryIndex to include index.php:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Restart the Apache server to enable the changes
sudo brew services restart httpd
Benefits:
- Compatibility: Homebrew Apache and PHP work perfectly together.
- Flexibility: Run both servers simultaneously for different projects.
- Control: Easily manage configurations and updates with Homebrew.
Facing this problem? Give this solution a try! Share your experiences in the comments below.