PHPInfo / Valet - Two different PHP versions
It is a classic source of confusion when your phpinfo() output displays one version while running php -v in your terminal reveals another. In the specific scenario described, you are running on macOS with Homebrew and Laravel Valet, seeing PHP 7.2.13 served by the web server but PHP 7.3.0 invoked from the command line. This discrepancy usually isn't a configuration error but rather a mismatch between what your application expects to load and which binary the system shell is actually executing.
When you run phpinfo() in a browser, you are looking at the output of the web server processâspecifically Nginx or Apache, depending on your setup. The path listed in the configuration file (/usr/local/etc/php/7.2) confirms that the web server was explicitly told to use the PHP 7.2 installation located there. Valet manages this by creating symlinks or modifying the php.ini path based on the version you selected during its setup.
Conversely, when you run php -v in your terminal, you are executing whatever binary is first found in your system's PATH. Your which php command correctly identifies /usr/local/bin/php as the active executable. If this binary corresponds to PHP 7.3.0, it means your shell environment has switched away from the version Valet is using for your local sites.
The root cause of this split often lies in how Homebrew handles multiple PHP versions or how the global PATH variable is constructed. You mentioned having /usr/local/etc/php/7.2 configured but potentially having PHP 7.3 installed elsewhere or as a symlink that took precedence in the shell environment. The fact that you cannot brew unlink php@7.2 suggests that version might not be installed via Homebrew's Cellar, but rather resides in a custom directory managed by Valet or an older installation that is no longer tracked by Homebrew.
To align these versions, you must ensure the web server process and your CLI session are pointing to the same executable binary. The most direct way to verify this on macOS is to check if /usr/local/bin/php is a symlink. If it points to a PHP 7.3 binary while Valet expects 7.2, you have a version conflict.
If you intend to use PHP 7.3 for your Laravel project, you need to update the configuration that Valet uses to point to that specific version. This involves modifying the ~/.config/valet/config.php file or reinstalling the specific PHP version you want Valet to serve. However, simply changing the config might not be enough if the binary path itself is incorrect.
A common pitfall occurs when developers mix Homebrew-managed PHP versions with global installations. If you have a symlink at /usr/local/bin/php pointing to 7.3, but Valet is configured to look for 7.2 in /usr/local/etc/php/7.2, restarting Nginx or Valet will not resolve the issue because the underlying binary paths are still disjointed.
The solution often involves cleaning up the environment to ensure consistency. You may need to remove the conflicting symlinks at /usr/local/bin/php and let Valet manage the correct version, or explicitly update your ~/.bash_profile to prioritize the directory where the desired PHP version resides before /usr/local/etc/php/7.2. Remember that Valet does not automatically switch its internal PHP binary location based on your shell's PATH; it relies on explicit configuration files in its own config directory.
If you are upgrading from 7.2 to 7.3, ensure that your Laravel application is compatible with the newer version before committing to the change. While PHP 7.3 offers performance improvements and security fixes, legacy code might require adjustments. Once the paths align and the configuration files point to the same binary, both phpinfo() and php -v will reflect the correct version, ensuring consistent behavior across your development workflow. For more in-depth guides on managing local environments with specific PHP versions, resources like https://laravelcompany.com can provide further context on best practices for Laravel development stacks.