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 Advertisement
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:
- 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
- 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.
- 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.
- 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
- 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
- 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.
1 Comment
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.