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.
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 on Intel Macs or /opt/homebrew/opt/php/bin on Apple Silicon) 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="/opt/homebrew/opt/php/bin:$PATH" (or /usr/local/opt/php/bin:$PATH for Intel Macs). After saving the file, reload your shell configuration by running source ~/.bash_profile (or source ~/.bashrc).
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, which 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. Note that --force may overwrite existing system PHP symlinks, so use it with caution.
If you have installed multiple versions of PHP using Homebrew, you can switch between them using brew unlink php && brew link php@<version>. For example, to switch to version 8.0, you can use the command brew unlink php && brew link [email protected].