[SOLVED] Laravel 5.1 Nginx/Apache: Can’t display errors, 500 internal server error

Standard

Edit index.php in public folder.

put all code inside try .. catch …


<?php

try {

require __DIR__.'/../bootstrap/autoload.php';

$app = require_once __DIR__.'/../bootstrap/app.php';

$kernel = $app->make('Illuminate\Contracts\Http\Kernel');

$response = $kernel->handle(
	$request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);


} catch(\Exception $e) {
    echo "<pre>";
    echo $e;
    echo "</pre>";
}

[Solved] Laravel Storage Permission Denied even chmod 777

Standard

By default, SELinux will block the ability for Apache/webapps to write to files in RHEL/Centos. This is a security feature to limit what folders Apache can write to. You can notice this issue if you get errors in your Apache/Nginx such as:

PHP Warning:  move_uploaded_file(): Unable to move ‘/path/to/upload/…’ to ‘…….’

Command to set permissions:

chcon -R -t httpd_sys_rw_content_t <folder_name>

You can check the SELinux permissions via the following command:

ls -halZ

If You get Laravel Storage Permission Denied even chmod 777 there is posibility it is caused by SELinux mode in the server. SELinux was enabled which prevent Apache/Nginx to write files even with 777 mode.

Check

 sudo setenforce 0

This should allow writing to storage directory, If permission denied gone, this prove SELinux is the problem. Turn SELinux back

setenforce 1

Then finally use SELinux to allow writing of the file by using this command

chcon -R -t httpd_sys_rw_content_t storage

And you’re off!