Skip to content

Instantly share code, notes, and snippets.

@wesamly
Last active February 13, 2022 14:21
Show Gist options
  • Save wesamly/764c5638ce8c256e6bacc3198ee63fea to your computer and use it in GitHub Desktop.
Save wesamly/764c5638ce8c256e6bacc3198ee63fea to your computer and use it in GitHub Desktop.
Homebrew php version per vhost

Reference: macOS 11 Big Sur Nginx Setup: Multiple PHP Versions

Other Refs:

PHP-FPM

How to setup macOS Multi PHP Development Environment with MySQL and phpmyadmin

Don’t use the default homebrew core tap for PHP. Use shivammathur/php.

brew tap shivammathur/php

brew install shivammathur/php/php@7.2
brew install shivammathur/php/php@7.3
brew install shivammathur/php/php@7.4
brew install shivammathur/php/php@8.0
brew install shivammathur/php/php@8.1

Next, set PHP 7.4 as your default php CLI version.

brew unlink php
brew link --overwrite --force php@7.4

Update /usr/local/etc/php/7.4/php-fpm.d/www.conf

# default
user = _www
group = _www
listen = 127.0.0.1:9000

# change to
user = <your_username>
group = staff
listen = 127.0.0.1:9074

Once you are ready, start-up php-fpm for each version.

brew services start php@7.2
brew services start php@7.3
brew services start php@7.4
brew services start php@8.0
brew services start php@8.1

Check that you have processes running and validate your ports are correct.

sudo lsof -i -n -P|grep php-fpm

Edit httpd.conf to enable the following modules:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

Restart Apache

Update VHost entry

<VirtualHost *:80>
	ServerAdmin email@example.com
	DocumentRoot "/Users/web/work/clients/kcpa/kcpatax"
	ServerName kcpatax.dv
   <Proxy "fcgi://127.0.0.1:9073">
    	ProxySet timeout=3600
   </Proxy>
  	<FilesMatch "\.php$">
  		SetHandler proxy:fcgi://127.0.0.1:9073
	</FilesMatch>
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment