Fix "The stream or file laravel.log failed to open stream: Permission denied" di Laravel 8 dengan Webserver Apache GNU/Linux


Assalamualaikum Wr.Wb..
dengan diberikan nikmat dan rezeki dari Allah SWT, saya Mr.Gagaltotal666 akan
berbagi kepada anda yaitu tentang cara mengatasi Fix "The stream or file
laravel.log failed to open stream: Permission denied" di Laravel 8
dengan Webserver Apache GNU/Linux.

ketika saat saya ingin membuat projeck directory baru
dan menaruh nya di directory root apache
ada kendala error saat membuka langsung directory /public di laravel 8
contoh sebagai berikut :

The stream or file "/var/www/html/laravel8/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied


cara mengatasi nya cukup mudah kok
tidak susah, oke ikut langkah berikut

error di atas memang sudah jelas dari hak akses/permission 
dari suatu directory, cukup perintah sebagai berikut untuk permission nya
menggunakan chmod dan kita kasih ke 777

contoh sebagai berikut

$ sudo chmod -R 777 storage/framework
$ sudo chmod -R 777 storage/logs
$ sudo chmod -R 777 bootstrap/cache

bisa juga seperti ini

$ chmod -R 777 /var/www/laravel-directory/storage/logs
$ chmod -R 777 /var/www/laravel-directory/storage/framework/views
$ chmod -R 777 /var/www/laravel-directory/storage/framework/sessions


ada sedikit tambahan untuk di .htaccess dan index.php
contoh seperti ini

buat file .htaccess, isi code seperti berikut

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

<Files .env>
Order allow,deny
Deny from all
</Files>

rename file server.php menjadi index.php
contoh isi code seperti berikut

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}else {
define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

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

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

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

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

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

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

$response->send();

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


nah kalau gini kamu tidak perlu repot membuat virtual host
kalau untuk di webserver apache ya, kalau nginx jangan deh
jadi kamu tinggal mainin php artisan beserta migrate, model,
dan membuat controller, jadi ini kesan nya tidak perlu repot
php artisan serve lagi, cukup copy di taruh directory root apache

buka kembali di browser project nya
done...


oke mungkin itu saja mengenai cara mengatasi error
Permission denied di laravel 8, kalau ada kesalahan
dan kekurangan nya mohon berikan masukan nya ya

sekian dan semoga bermanfaat...

Wasalamualaikum Wr.Wb...

Post a Comment

0 Comments