Issue:
When encountering the following errors:
Warning: file_get_contents(/var/root/.valet/config.json): failed to open stream: Permission denied in /Users/Username/.composer/vendor/laravel/valet/server.php on line 23
Warning: Invalid argument supplied for foreach() in /Users/Username/.composer/vendor/laravel/valet/server.php on line 47
404 - Not Found
Solution:
These errors are related to permissions and ownership of files, particularly when using globally installed Composer packages with sudo. The server.php script in the laravel/valet package checks the file owner to set the VALET_HOME_PATH. To resolve this, you can adjust the ownership of either all global packages or specifically the laravel/valet package. It is recommended to change ownership for all global packages to avoid potential issues with future Composer updates or installations without sudo.
To change ownership of the global Composer packages, follow these steps:
- Open a terminal window.
- Navigate to the Composer directory:
cd ~/.composer/
- Change ownership of the
vendordirectory to your current user:sudo chown -R $(whoami) vendor
Reference:
For more detailed discussion on this issue and solution, you can visit: https://laracasts.com/discuss/channels/general-discussion/getting-valet-not-found-error