Install php Multi version
Day by day everything are moving or changing it's not like how I love my wife still the same 😅 . Anyway this content we are talking about how to install and use PHP multi version in the one computer(Mac).
So why multi PHP version?
Installing :
brew tap shivammathur/phpbrew install shivammathur/php/php@7.2brew install shivammathur/php/php@7.3brew install shivammathur/php/php@7.4brew install shivammathur/php/php@8.0brew install shivammathur/php/php@8.1
Tell computer to use one PHP version as default
brew unlink phpbrew link --overwrite --force php@7.4
In case you want to switch to any version you can just update php@version
After doing this you can test on terminal by type php -v to see if it work
Define port to each version
code /usr/local/etc/php/7.4/php-fpm.d/www.conf
Apple Silicon M1 Chipset
code /opt/homebrew/etc/php/7.4/php-fpm.d/www.conf
Update content below to change your port and port will be used for php-fpm to separate each version
This way you can config your Apache or Nginx to use PHP by 127.0.0.1:port . Totally port is represent of PHP version.
# default
user = _www
group = _www
listen = 127.0.0.1:9000
# change to
user = {your_username}
group = _www
listen = 127.0.0.1:9074
Restart
brew services restart php@7.4 or your php versionbrew services restart nginx
Create shortcut
ln -s /usr/local/opt/php@8.1/bin/php /usr/local/bin/php81
Then you can try php81 -v to verify if it work.
So for project that using php 8.1 you just use php81 instead of php
Good luck!