A local development setup for PHP projects:
- macOS
- Apache (
httpd) - MySQL
- PHP-FPM (multiple versions)
.localhostdomains (nomkcertordnsmasqrequired)
Important
This guide uses /Users/<USERNAME>/www as a custom local web root.
Replace <USERNAME> with your macOS username and create that directory.
Install and start MySQL:
brew install mysql
brew services start mysqlRun this to remove insecure defaults from a fresh local install:
mysql_secure_installationUse these answers:
- Password validation plugin: no
- Set root password: yes (example:
rootfor local dev) - Remove anonymous users: yes
- Disallow remote root login: yes
- Remove test database: yes
- Reload privilege tables: yes
Install and start Apache:
brew install httpd
brew services start httpdConfigure Apache:
vim /opt/homebrew/etc/httpd/httpd.conf- Find and uncomment the following lines (remove leading
#):
LoadModule rewrite_module ...
LoadModule proxy_module ...
LoadModule proxy_fcgi_module ...- Find and edit these directives to match:
Listen 80
Include /Users/<USERNAME>/www/httpd-vhosts.conf- Add this directory access block:
<Directory "/Users/<USERNAME>/www">
AllowOverride All
Require all granted
DirectoryIndex index.php index.html
</Directory>Restart Apache:
brew services restart httpdInstall multiple PHP versions as needed:
brew install php@8.3 php@8.4Configure dedicated ports for each PHP-FPM pool:
php@8.3->127.0.0.1:9083php@8.4->127.0.0.1:9084
vim /opt/homebrew/etc/php/8.3/php-fpm.d/www.conf
listen = 127.0.0.1:9083
pm = ondemand
pm.max_children = 15vim /opt/homebrew/etc/php/8.4/php-fpm.d/www.conf
listen = 127.0.0.1:9084
pm = ondemand
pm.max_children = 15Start PHP-FPM services:
brew services start php@8.3 php@8.4Create or edit your vhosts file:
vim ~/www/httpd-vhosts.confAdd one vhost per project:
<VirtualHost *:80>
ServerName example.localhost
DocumentRoot "/Users/<USERNAME>/www/example"
AddHandler proxy:fcgi://127.0.0.1:9083 .php
</VirtualHost>Choose the AddHandler port per project PHP version:
- PHP 8.3:
AddHandler proxy:fcgi://127.0.0.1:9083 .php - PHP 8.4:
AddHandler proxy:fcgi://127.0.0.1:9084 .php
Restart Apache:
brew services restart httpdOpen website:
http://example.localhost
If you use Git worktrees and want each worktree to run on its own .localhost subdomain, check out Apache Wildcard Domains for Worktrees.
To apply this setup with a coding agent, use the Bleech
localhost-mamp-worktreesskill: https://github.com/bleech/skills/tree/main/localhost-mamp-worktrees