How to install or uninstall PHP

Install PHP 7.4 using Homebrew

1 – First, we need to know if we already have PHP installed in our system by executing the command;

php --version

2 – If we don’t have PHP installed then we can proceed to the next step

3 – Copy and paste the following commands into your Terminal

brew tap shivammathur/php
brew install shivammathur/php/php@7.4
brew link php@7.4

Uninstall PHP 7.4 using Homebrew

1 – Find out what was the name of the PHP when it was first installed. Sometimes it comes with the version number such as “php@8.2” or sometimes its just “php” Copy and execute the command below

brew list 

2 – Then run the following command to start the uninstall (in my case, the first installation is named as “php” ;

rm -rf $(brew --repo homebrew/core)
brew tap homebrew/core
brew uninstall php