I’m hosting a Laravel project inside a RHEL 7 machine using NGINX and PHP7.4-fpm
in my nginx.conf
, I set the user as the following
user nexta;
while in my .../.../php-fpm.d/www.conf
user = nexta
group = nexta
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nexta
listen.group = nexta
listen.mode = 0660
Using this setup, I managed to run the Laravel application, however, I am stuck with the permission denied error
It says:
The stream or file "/home/nexta/mywebsite.com/storage/logs/laravel-2021-07-25.log" could not be opened in append mode: failed to open stream: Permission denied
I have tried the followings
- Setting the chown and chmod
sudo chown -R nexta:nexta /home/nexta/mywebsite.com
sudo chown -R nexta:nexta /home/nexta/mywebsite.com/storage
sudo chown -R nexta:nexta /home/nexta/mywebsite.com/bootstrap/cache
sudo chmod -R 775 /home/nexta/mywebsite.com/storage
sudo chmod -R 775 /home/nexta/mywebsite.com/bootstrap/cache
- tried to use 777 (I know it’s not a good practice)
sudo chmod -R 777 /home/nexta/mywebsite.com/storage
sudo chmod -R 777 /home/nexta/mywebsite.com/bootstrap/cache
-
changed the user in nginx.conf to nginx and chown the site to nginx. The error still prevails and also I am unable to view my application
-
Ran the followings:
php artisan cache:clear
composer dumpautoload
What I also noticed, if I run php artisan cahce:clear
(notice the typo), this triggers an error and the app able to access the log file, yet the when the app is accessed through http request, the app is unable to access the log file.
I also try to echo whoami
in the php request (using a non laravel application), I got the following response
Returned with status 0 and output: Array ( [0] => nexta )
which means, when the app is executed by http request, the user is nexta.
At this point, I’m not even sure what causes the error.
2
Answers
For whatever reason, the following command fix my issue
You should have a lock on the file for any reason.
You can solve he pb by either :
or if you want to keep it