Andikatama
Andikatama

Reputation: 92

Cannot Access Laravel Public Folder in Live Ubuntu Server

Problem: I can't access all file in public folder, but when i'm in index.php there is no problem.

This is my index.php screenshot There is some image that's not loaded, when i inspect element, i get this error: Same result when, i'm manually write url in browser like this, I've already checked in server, the file is exists

I've just provide my index.php screenshot, there is some asset(image,css,js) that's not loaded, when i inspect element, i get 404 error. Same result when, i'm manually write url in browser, I've already checked in server, the file is exists.

This problem only happens in live server, when in development environment this problem isn't happening. All file is same, cause i'm just cloning it from local to my live server

Server and project description:

Some parts on my .env in live server:

APP_NAME="Everbright Web Integrated"
APP_ENV=production
APP_KEY=base64:xxx
APP_DEBUG=false
APP_TIMEZONE=UTC
APP_URL=https://192.168.8.210:443

Things already do:

  1. php artisan storage:link -> result fail
  2. set permission in public folder to 777 -> result fail
  3. manually check file is exists -> result fail
  4. change env to productionn -> result fail

I'm expecting there is no 404 error when access file in public folder

Apache directives in /etc/apache2/sites-available/xxx.conf that apply to this virtual server

DocumentRoot /home/public_html/ewi/public
ServerAdmin xxx
SSLEngine on
SSLCertificateFile /etc/apache2/xxx
SSLCertificateKeyFile /etc/apache2/xxx
<Directory /home/public_html/ewi>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # 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]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
ErrorLog ${APACHE_LOG_DIR}/demo-error.log
CustomLog ${APACHE_LOG_DIR}/demo-access.log combined

enter image description here

Here my routes file :

<?php
    
    
use Illuminate\Support\Facades\Auth;

use Illuminate\Support\Facades\Route;
    
    
Route::get('/', function () {
        if (Auth::check()) {
            return view('home', ['kdSupp' => Auth::user()->kdsupp]);
        } else {
            return view('welcome');
        }
    });
    
    
Auth::routes();
    
    
Route::get('/list-supp', [App\Http\Controllers\WebRequestController::class, 'listSupplier']);
    
    
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
    

// Surat Jalan
    
Route::get('/surat-jalan/upload', [App\Http\Controllers\SuratJalanController::class, 'index']);
    
Route::get('/surat-jalan/view', [App\Http\Controllers\SuratJalanController::class, 'lihatSuratJalan']);
    
Route::get('/surat-jalan/detail/{id}', [App\Http\Controllers\SuratJalanController::class, 'lihatDetailSuratJalan']);
    
Route::post('/surat-jalan/upload', [App\Http\Controllers\SuratJalanController::class, 'importExcel']);
    
Route::patch('/surat-jalan/ubah', [App\Http\Controllers\SuratJalanController::class, 'ubahSuratJalan']);
    
Route::patch('/surat-jalan/ubah-item', [App\Http\Controllers\SuratJalanController::class, 'ubahItemSuratJalan']);
    
Route::delete('/surat-jalan/hapus', [App\Http\Controllers\SuratJalanController::class, 'hapusSuratJalan']);
    
Route::delete('/surat-jalan/hapus-item', [App\Http\Controllers\SuratJalanController::class, 'hapusItemSuratJalan']);
    
// End Surat Jalan
    
    

//Invoice
    
Route::get('/invoice/upload', [App\Http\Controllers\InvoiceController::class, 'index']);
    
Route::get('/invoice/view', [App\Http\Controllers\InvoiceController::class, 'lihatInvoice']);
    
Route::get('/invoice/detail/{id}', [App\Http\Controllers\InvoiceController::class, 'lihatDetailInvoice']);
    
Route::post('/invoice/upload', [App\Http\Controllers\InvoiceController::class, 'importExcel']);
    
Route::patch('/invoice/ubah', [App\Http\Controllers\InvoiceController::class, 'ubahInvoice']);
    
Route::patch('/invoice/ubah-harga', [App\Http\Controllers\InvoiceController::class, 'ubahHarga']);
    
Route::delete('/invoice/hapus', [App\Http\Controllers\InvoiceController::class, 'hapusInvoice']);
    
Route::delete('/invoice/hapus-sj', [App\Http\Controllers\InvoiceController::class, 'hapusSuratJalan']);
    
//End Invoice

//Faktur Pajak
    
Route::get('/faktur-pajak/upload', [App\Http\Controllers\FakturPajakController::class, 'index']);
    
Route::get('/faktur-pajak/view', [App\Http\Controllers\FakturPajakController::class, 'lihatFakturPajak']);
    
Route::get('/faktur-pajak/detail/{id}', [App\Http\Controllers\FakturPajakController::class, 'lihatDetailFakturPajak']);
    
Route::post('/faktur-pajak/upload', [App\Http\Controllers\FakturPajakController::class, 'importExcel']);
    
Route::patch('/faktur-pajak/ubah', [App\Http\Controllers\FakturPajakController::class, 'ubahFP']);
    
Route::patch('/faktur-pajak/ubah-invoice', [App\Http\Controllers\FakturPajakController::class, 'ubahInvoice']);
    
Route::delete('/faktur-pajak/hapus', [App\Http\Controllers\FakturPajakController::class, 'hapusFP']);
    
Route::delete('/faktur-pajak/hapus-invoice', [App\Http\Controllers\FakturPajakController::class, 'hapusInvoice']);
    
//End Faktur Pajak
    
    

Route::post('/upload-excel', [App\Http\Controllers\UploadController::class, 'prosesUpload']);
    // Download Route
    Route::get('download/template/{filename}', function ($filename) {
        // Check if file exists in app/storage/file folder
        $file_path = storage_path() . '/file/' . $filename;
        if (file_exists($file_path)) {
            // Send Download
            return Response::download($file_path, $filename, [
                'Content-Length: ' . filesize($file_path)
            ]);
        } else {
            // Error
            exit('Requested file does not exist on our server!');
        }
    })
        ->where('filename', '[A-Za-z0-9\-\_\.]+');
    

Upvotes: 1

Views: 129

Answers (2)

Andikatama
Andikatama

Reputation: 92

Finally found the solution of this problem. I just delete this line in apache conf file

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

I don't know what that line mean, i just follow other SO solution, but realize something strange, so i delete that line and all is solved

Upvotes: 0

Ahmed Abdelnaby
Ahmed Abdelnaby

Reputation: 9

Enable mod_rewrite Module:

sudo a2enmod rewrite
sudo systemctl restart apache2

Check Apache User:

Open the Apache configuration file /etc/apache2/apache2.conf or /etc/httpd/conf/httpd.conf.

change the ownership of the public directory to www-data

sudo chown -R www-data:www-data /home/public_html/ewi/public

Clear Cache

php artisan config:cache
php artisan route:cache
php artisan view:cache

Upvotes: 0

Related Questions