How to use the php that brew installed?

To use the PHP that Homebrew installed, you will first need to make sure that it is in your system's PATH. You can do this by running the command echo $PATH in your terminal and checking if the path to the Homebrew PHP executable (e.g. /usr/local/opt/php/bin) is included. If it is not, you can add it to your PATH by editing your shell profile file (e.g. ~/.bash_profile or ~/.bashrc) and adding the line export PATH="/usr/local/opt/php/bin:$PATH".

Once you've done that, you should be able to run the php command in your terminal and see the version of PHP that Homebrew installed. You can also use this version of PHP to run PHP scripts by running the command php path/to/script.php.

Alternatively, you can use the command brew link --force php that will create a symlink to the version of PHP that you have installed via Homebrew in the /usr/local/bin directory, which is automatically added to the PATH variable.

If you have installed multiple versions of PHP using Homebrew, you can switch between them using the brew switch command. For example, to switch to version 8.0.24, you can use the command brew switch php 8.0.24.