I’ve been developing in Laravel 10 in my local, and seeing the web using php artisan serve
then I uploaded all those files to a webserver, updated .env file with the new DB and url data, and tried a couple of times and work ok!! But after some hours, it stoped working. I can access the root folder and see the Laravel main screen, but if I want to access some controller it says "Target class does not exists".
I guess it worked on local, and then on the server the firsts times, until some cache refreshed and then it didn’t work anymore.
I accessed the webserver through ssh and run:
composer update
composer install --optimize-autoloader --no-dev as
php artisan cache:clear
php artisan route:clear
php artisan optimize:clear
But nothing seems to work. Any idea what could be happening?
Error: https://flareapp.io/share/q5YWO0eP
EDIT: If I add add the namespace in the route like this
Route::get('/landing', 'AppHttpControllersLandingController@index');
instead of this:
Route::get('/landing', 'LandingController@index');
it works fine! But I need to know WHY on local it works without adding the namespace and in the webserver it doesn’t!
3
Answers
from the error uploaded , it seems like the LandingController file does not exist or is not well named (check namespaces) and the controller exist.
run a
to confirm you are not getting the same error.
also you might want to check your route service provider file to be sure its is set to ‘namespace’ => ‘AppHttpControllers’
first make sure you’ve got your namespace and class name in check for that LandingController. Make sure it’s all spelt right and in the right directory. You know how PHP is picky about that case sensitivity stuff, so keep an eye out for that too.
You mentioned you did the composer song and dance with composer dump-autoload, which is a good move. That helps with autoloading, so props for that. also, don’t forget to give those cache gremlins the boot! Run
and one more think the permissions can be real finicky, so make sure your files and folders are playing nice with the web server. No one likes a party crasher, especially when it’s a permission issue.
it seems like you have one main application(https://www.rucalaf.com/) and you deploy your Laravel application inside a subdirectory(rucacrm) and access through URL segment i.e https://www.rucalaf.com/rucacrm/public.
When you were doing local development, at that time you don’t have such a folders segment environment, you were just using
localhost:8000
.The solution could be to change the line in the ".htaccess" file in the root folder from
RewriteRule ^ index.php [L]
toRewriteRule ^ /index.php [L]
However, this could be weird to deploy in a subfolder. You have to update the .htaccess redirection rules, assets serving, and so on. As your main application could have its own htaccess rules and so on.
You can read from here – https://lucabecchetti.medium.com/configure-laravel-to-work-in-a-subdirectory-and-with-artisan-serve-at-the-same-time-654ba0c1fd0b
But I suggest creating a subdomain and deploying your Laravel application there.