0

Using: Apache, CentOS 7, Laravel 6.x (to be updated next)

Problem: After successful installation of laravel (default page showing), I have moved my local development files over. Now before replacing the default routes/web.php I wanted to check if things were OK. I added one of the routes, using a just uploaded controller and view.

When I try to access this page (..../profile) it shows following error:

include(.../Controller.php): failed to open stream: Permission denied

Whereas the default page (.../) still works as normal.

What I have done to attempt to fix:

sudo chown -R apache.apache /var/www/.../laravel
sudo chmod -R 755 /var/www/.../laravel/storage
sudo chmod -R 755 /var/www/.../laravel/bootstrap/cache
sudo php artisan view:cache

All files (including the default view) are owned by apache.apace, so ownership is the same. As per directory permissions I have set the storage and bootstrap/cache folders (https://laravel.com/docs/6.x). How can this be fixed? I am out of idea to fix this...

I can find loads of examples of people with a similar issue, but they seem in the end to be related to permission on /storage or /bootstrap/cache. This seems not related to those, and as a result all suggestions provided did not solve this.

Siva
  • 1,481
  • 1
  • 18
  • 29

1 Answers1

0

Solved: I found this resource (Permissions Issue with Laravel on CentOS) which claims it may be related to selinux.

When I perform:

setenforce 0

the controller can be accessed, and site loads as expected. As it is not proper in terms of security, I turn it back on:

setenforce 1

now the same errors is back:

failed to open stream: Permission denied

I then managed to fix it by performing the following commands, using semanage fcontext to manage the default file system labeling on an SELinux system as suggested in the link above by the second answer:

sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/.../laravel/storage(/.*)?"
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/.../laravel/bootstrap/cache(/.*)?"
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/.../laravel/config(/.*)?"
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/.../laravel/app(/.*)?"
restorecon -Rv /var/www/bikegeartracker.com/laravel/

Now I am not an expert in SELinux in any way, but I can only assume that this probably has an effect on the security.