Home >Backend Development >PHP Tutorial >How to Fix 'file_put_contents(): failed to open stream: Permission denied' Error in Laravel?

How to Fix 'file_put_contents(): failed to open stream: Permission denied' Error in Laravel?

Susan Sarandon
Susan SarandonOriginal
2024-11-05 18:48:02877browse

How to Fix

Resolving "file_put_contents(meta/services.json): failed to open stream: Permission denied" Error

When attempting to access http://localhost/test/public/ and encountering the "Error in exception handler" message, several steps can be taken to diagnose and resolve the issue.

Step 1: Permission Modification

After verifying that debug is set to true in app.php, one may notice the following error: "The stream or file "/var/www/html/test/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied." To address this, run the command chmod -R 644 app/storage.

Step 2: Further Investigation

Upon resolving the previous error, a new one may appear: "file_put_contents(/var/www/html/laravel/app/storage/meta/services.json): failed to open stream: Permission denied."

Solution:

To resolve this issue, follow the steps suggested by vsmoraes:

For Laravel >= 5.4:

  1. Run php artisan cache:clear
  2. Run chmod -R 775 storage/
  3. Run composer dump-autoload

For Laravel < 5.4:

  1. Run php artisan cache:clear
  2. Run chmod -R 775 app/storage
  3. Run composer dump-autoload

The above is the detailed content of How to Fix 'file_put_contents(): failed to open stream: Permission denied' Error in Laravel?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn