Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»PHP Framework»Laravel Exception: The stream or file could not be opened: failed to open stream: Permission denied

    Laravel Exception: The stream or file could not be opened: failed to open stream: Permission denied

    By RahulDecember 26, 20222 Mins Read

    Error:

    One of my Laravel applications started showing the following error after I restarted the instance. The error message is:

    The stream or file “/var/www/html/storage/logs/laravel.log” could not be opened: failed to open stream: Permission denied

    Solution:

    This error message indicates that the PHP process that is trying to write to the log file does not have sufficient permissions to do so. There are a few things you can try to fix this issue:

    1. Check the ownership and permissions of the log file and its parent directories. The PHP process must have read and write permissions on the file and its parent directories. You can use the `ls -l` command to check the ownership and permissions of the file and chmod and chown to modify them if necessary.
      chmod -R 777 /var/www/html/storage 
      
    2. Make sure that the PHP process is running as the correct user. If the PHP process is running as a different user than the owner of the log file, it may not have sufficient permissions to write to the file. You can check with the user that the PHP process is running by using the ps command.
    3. Check the PHP error log for more information. The PHP error log may contain more detailed information about the error, including the exact line of code that caused the issue. The location of the PHP error log is usually specified in the php.ini configuration file.
    4. Make sure that the log file exists and is writable by the PHP process. If the log file does not exist, the PHP process will not be able to write to it. You can create the log file and set the correct permissions using the `touch` and `chmod` commands.
      touch /var/www/html/storage/logs/laravel.log 
      chmod 777 /var/www/html/storage/logs/laravel.log 
      
    5. The CentOS and other Redhat system users may have SELinux enabled. You can set the proper SELinux policy for the `storage` directory with the following command.
      chcon -R -t httpd_sys_rw_content_t /var/www/html/storage 
      
    6. The following commands will help you to create all required storage related directories.
      mkdir -p /path/to/laravel/storage/{app,framework,logs} 
      mkdir -p /path/to/laravel/storage/framework/{cache,sessions,views} 
      

      Then chnage the directoires owner and assign the full privileges to everyone:

      chmod -R 777 /path/to/laravel/storage/ 
      chown -R www-data:www-data /path/to/laravel/storage/ 
      

      Make sure to change `/path/to/laravel` with your Laravel application directory.

    I hope these suggestions help. Let me know if you have any questions or if you need further assistance.

    Error log Laravel
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Resolving ‘laravel.log could not be opened’: Step by Step Solutions

    How to enable debug mode in Laravel for specific environments

    Running Laravel Queue Worker as a Systemd Service

    View 1 Comment

    1 Comment

    1. anyini on March 29, 2023 3:22 pm

      Hey… this information save my project, two days searching the solution and this steps working form my project in laravel 8.

      Thanks… send me your data for donate you something when pay me…

      Apologize the bad english.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Difference Between Full Virtualization vs Paravirtualization
    • Virtualization vs. Containerization: A Comparative Analysis
    • Using .env Files in Django
    • Using .env File in FastAPI
    • Setting Up Email Notifications for Django Error Reporting
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.