skip to Main Content

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:

  • Ubuntu 22
  • PHP 8
  • Node JS 18
  • NPM 10
  • I’m using laravel 11

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 IlluminateSupportFacadesAuth;

use IlluminateSupportFacadesRoute;
    
    
Route::get('/', function () {
        if (Auth::check()) {
            return view('home', ['kdSupp' => Auth::user()->kdsupp]);
        } else {
            return view('welcome');
        }
    });
    
    
Auth::routes();
    
    
Route::get('/list-supp', [AppHttpControllersWebRequestController::class, 'listSupplier']);
    
    
Route::get('/home', [AppHttpControllersHomeController::class, 'index'])->name('home');
    

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

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

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

Route::post('/upload-excel', [AppHttpControllersUploadController::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-_.]+');
    

2

Answers


  1. Chosen as BEST ANSWER

    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


  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search