Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook 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 20, 20222 Mins ReadUpdated:December 26, 2022

    Error:

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

    Advertisement

    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

    Setting up CodeIgniter on Ubuntu: A guide for web developers

    How To Set Up Laravel on Ubuntu 21.04 & 20.10

    How to Enable Debug Mode in Laravel

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Error: EACCES: permission denied, scandir (Resolved)
    • How To Install Python 3.11 on Ubuntu 22.04 / 20.04
    • How to Install Python 3.11 on Amazon Linux 2
    • An Introduction to the “./configure” Command: Compiling Source Code in Linux
    • How to Install PHP 8.x on Pop!_OS
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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