Reputation: 48758
I'm trying to run a simple Laravel command line on my Elastic Beanstalk instance: php artisan queue:work
But I keep getting the following error:
In StreamHandler.php line 107:
The stream or file "/var/app/current/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
I've tried every solution I can find on SO (except the chmod -R 777
advice that seems to trail this question everywhere).
I've tried deleting the existing laravel.log
and then using touch
to create a new one, and then making sure webapp
is the owner.
I've also tried:
sudo chmod -R 755 /var/app/current/storage/
sudo chown -R webapp /var/app/current/storage/
When I list the logs directory, everything looks as I think it should:
-rwxr-xr-x 1 webapp webapp 0 Apr 4 14:38 laravel.log
The storage directory also looks fine:
drwxr-xr-x 6 webapp webapp 4096 Apr 3 19:33 storage
But I'm still getting the above error! Can anyone explain why (not just give a solution).
Thank you
Upvotes: 1
Views: 5253
Reputation: 4668
When you log into an EBS instance via ssh, you're logged in as ec2-user
.
I don't believe the ec2-user
is part of the webapp
group which is actually executing PHP & apache/nginx.
Try adding your ec2-user
to the webapp group by creating an ebextension in the root of your Laravel project under .ebextensions/ec2user.config
users:
ec2-user:
groups:
- webapp
Upvotes: 2
Reputation: 1842
Prove this is the problem by turning off selinux with the command
sudo setenforce 0
This should allow writing, but you've turned off added security server-wide. That's bad. Turn SELinux back
sudo setenforce 1
Then finally use SELinux to allow writing of the file by using this command
sudo chcon -R -t httpd_sys_rw_content_t storage
And you're off!
Upvotes: 0
Reputation: 48758
So the simple answer is that I was running the command as ec2-user
. As a solution, I could either:
ec2-user
sudo -u webapp php artisan queue:work
)sudo su
to see how it would be run during deployment (ie. as root
)Nothing was especially wrong.
Upvotes: 4