bpaneru's avatar

Laravel + Livewire, some routes not loading on production.

I am working on Laravel 10 on top of Breeze with Livewire using full page components.

In my web.php I have routes:

/** only relevant code included **/

use App\Http\Livewire\Dashboard;
use App\Http\Livewire\Equipment;
use App\Http\Livewire\ManageUser;
use App\Http\Livewire\Searchanpr;
use App\Http\Livewire\Sitepage;

Route::middleware(['auth', 'verified'])->group(function(){
    Route::get('/dashboard', Dashboard::class)->name('dashboard');
    Route::get('/anprvehicle', Searchanpr::class)->name('anpr');
});

Route::middleware(['auth', 'verified', 'admin'])->group(function(){
    Route::get('/equipment', Equipment::class)->name('equipment');
    Route::get('/sitemgmt', Sitepage::class)->name('site');
    Route::get('/usermgmt', ManageUser::class)->name('usermgmt');
});

When checking routes with php artisan route:list all the routes exist.

/** only relevant routes displayed **/
GET|HEAD  anprvehicle ................................................... anpr › App\Http\Livewire\Searchanpr
GET|HEAD  dashboard................................................... dashboard › App\Http\Livewire\Dashboard
GET|HEAD  equipment ................................................... equipemnt › App\Http\Livewire\Equipment
GET|HEAD  sitemgmt ................................................... site › App\Http\Livewire\Sitepage
GET|HEAD  usermgmt ................................................... usermgmt › App\Http\Livewire\ManageUser

Locally, using WSL 2 with Docker all the routes load fine in sail. But on production, azure web server with linux, the site and anpr routes return 404 not found from nginx (not the laravel 404 not found).

This is my startup.sh

#!/bin/bash
cp /home/site/wwwroot/azure-app-service/nginx.conf /etc/nginx/sites-available/default && service nginx restart
echo "Copied Laravel Configuration File to nginx directory & restarted nginx"
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh |bash
echo "Installed NVM Node verison manager"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
nvm install node
echo "Installed node & npm"
npm install
echo "ran npm install"
npm run build
echo "ran npm build"
php artisan optimize:clear
echo "Cleared all cache and config files"
php artisan optimize
echo "optimized all cache and config files"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
mv composer.phar /usr/local/bin/composer
echo "Composer downloaded installed and made global"
php -r "unlink('composer-setup.php');"
composer install --optimize-autoloader --no-dev
echo "Composer's class autoloader map optimized"

I run dos2unix startup.sh, after it has been modified, before pushing to azure

The default nginx.conf did not work for me so I am using this nginx.conf

In production, I am able to login, access the dashboard, equipment and usermgmt but anprvehicle and sitemgmt can`t be accessed.

When I initially had dashboard, anprvehicle, equipment and sitemgmt I was not able to access just sitemgmt which I thought might be fixed when I push into the repo but now I cannot access both anprvehicle and sitemgmt

Please let me know If I am missing anything.

0 likes
5 replies
vincent15000's avatar
Level 63

Have you cached your routes ?

php artisan route:cache
2 likes
bpaneru's avatar

@vincent15000 I was under the impression that php artisan optimize cached everything again, in contrast to php artisan optimize:clear which clears all the cached files. However, I have updated the startup.sh to include all caching commands mentioned in the documentation at the end. I am still not able to access the said pages.

/** Preceding codes **/
composer install --optimize-autoloader --no-dev
echo "Composer's class autoloader map optimized"
php artisan config:cache
php artisan event:cache
php artisan route:cache
php artisan view:cache
echo " Config, Event, Route and View information cached"
1 like
bi3_dev's avatar

@bpaneru Have you found the solution to this issue yet ? I'm also having similar problem

1 like
Randy_Johnson's avatar
php artisan route:clear
php artisan route:cache

Please mark that the answer was found.

bpaneru's avatar

After trying almost everything I ended up creating a new project again from scratch and then I figured out that the issue was caused because there was still errors in my code and in production the error is not displayed rather Nginx simply throws 404 not found (not the Laravel 404). I was always working with fake data using seeders in local environment and never had any issues with data not being found. Rookie mistake, Lesson learned. If anyone else comes across similar problem and nothing works, the solution might be to test the web app by replicating the production environment locally to see if any errors are there, in my case it was null reference error.

Please or to participate in this conversation.