brew link php71: Could not symlink sbin/php-fpm

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Troubleshooting Homebrew Linking: Fixing Errors When Installing PHP for Laravel Valet Setting up local development environments on macOS often involves managing system dependencies, and using Homebrew is the standard approach for this. However, as we’ve seen with the error message `Could not symlink sbin/php-fpm`, linking issues can derail even simple setup tasks like installing Laravel Valet. If you are trying to install PHP 7.1 via Homebrew to support an older project or dependency, running into permission errors during the `brew link` process is a common hurdle. As a senior developer, understanding *why* these links break and how to fix them is crucial for maintaining reliable development environments, especially when working within the Laravel ecosystem where version compatibility is paramount, as emphasized by resources like [laravelcompany.com](https://laravelcompany.com). This post will diagnose the exact problem you are facing and provide a step-by-step solution to get your PHP environment properly linked and ready for Valet. ## Diagnosing the Homebrew Linking Failure The error messages you are seeing—specifically concerning `sbin/php-fpm` and `/usr/local/sbin is not writable`—indicate a classic permissions or path issue rather than a failure in compiling the PHP code itself. When Homebrew attempts to link a formula (like `php71`) into the system directories (`/usr/local/bin`, `/usr/local/sbin`), it requires write access to those locations. If you are running commands without sufficient privileges, or if previous failed operations left the permissions in an inconsistent state, the linking process halts. The fact that `php -v` still shows PHP 7.1.7 suggests that a version of PHP was installed somewhere on your system, but Homebrew's management structure is broken. This mismatch between what the shell finds and what Valet expects (the "Unable to determine linked PHP" error) confirms that the environment variable linking failed. ## Solutions: Rebuilding and Forcing the Link Since the initial attempt failed due to permissions, we need to force Homebrew to re-evaluate and correct those links. Here are the most effective methods to resolve this issue. ### 1. Clean Up and Reinstall Dependencies Before attempting a fresh link, it is best practice to clean up any potentially corrupted files and ensure your environment is clean. ```bash # 1. Clean up any old installations related to PHP 7.1 attempt brew cleanup # 2. Attempt the install again (this often resolves temporary state issues) brew install php71 ``` ### 2. Addressing Permissions with `sudo` (Use with Caution) If standard linking fails due to strict permissions, you might need to use `sudo`. Be aware that using `sudo` within Homebrew commands should be done sparingly, as it grants elevated privileges. ```bash # Attempting the link again with elevated permissions sudo brew link php71 ``` If this command succeeds, it means the linker had the necessary rights to create the symbolic links in `/usr/local`. If you encounter further permission errors here, it might indicate a deeper system configuration issue that requires checking your overall Homebrew setup. ### 3. The Alternative: Using `brew unlink` and Re-linking If simply running `brew link` repeatedly fails, manually unlinking any potentially broken previous links and then linking everything can often reset the state correctly. ```bash # Unlink any existing broken links for php71 (if any exist) brew unlink php71 # Now attempt the full link process again brew link php71 ``` ## Conclusion: Maintaining a Stable Development Environment Troubleshooting build and linking errors is an essential part of being an effective developer. The issue you faced is rooted in file system permissions, not necessarily a faulty PHP compilation. By systematically cleaning up the environment and using targeted commands like `brew unlink` or carefully applying `sudo`, you can force Homebrew to establish the correct symbolic links required by tools like Laravel Valet. Always ensure your Homebrew installation is up-to-date (`brew update`) before starting complex operations. A stable foundation, managed correctly, is key to building robust applications within the modern PHP landscape. Happy coding!