-1

I'm learning Laravel, I just uploaded my project to web hosting. But when I run the website, I get the error message

file_put_contents() failed to open stream no such file or directory hosting

Then I tried to reset-cache:

php artisan config:clear
php artisan event:clear
php artisan route:clear
php artisan view:clear
php artisan view:cache
php artisan route:cache
php artisan event:cache
php artisan config:cache

After I ran the command, another error message appeared:

Target class [App\Http\Controllers\PageController] does not exist.

I've made sure that the PageController is in the App\Http\Controllers directory.

What happened? How do I fix it?

I've tried clearing cache, changing routes, but nothing works.

10
  • How did you deploy your app? git? copy paste via ftp? if all files were properly added in the right places, try to run composer dump-autoload Commented Sep 26, 2023 at 2:53
  • @Mr.Kenneth I just copy paste the project via FTP. The web hosting I have does not have a CLI/terminal feature, so I run a cache reset using Artisan::call, unfortunately, I have tried calling dump-autoload via Artisan::call('sump-autoload') but it doesn't work, I get the error message "The command "dump -autoload"does not exist.". Are there any steps I missed before uploading the project? Commented Sep 26, 2023 at 3:04
  • 1
    Welcome to SO ... is the filename for this Controller PageController.php and the class defined in it is PageController? trying to rule out case sensitivity issues with the filesystem Commented Sep 26, 2023 at 3:14
  • 1
    Make sure the namespace is correct Commented Sep 26, 2023 at 3:19
  • @lagbox Hi, yes that's right, I'm sure that the filename and class defined was correct, I even copied and pasted the file name into the defined section. Commented Sep 26, 2023 at 3:24

1 Answer 1

1

if your page is 404, that mean error on route, you can check your route:list and make sure the route has been detected, and do php artisan optimize

if your controller does not exist, maybe you forgot to write use or maybe typo, it happen a lot at me too

use Illuminate\Support\Facades\Route;
// ADD THIS ! dont forget use
use App\Http\Controllers\SomeController;

Route::get('something', [SomeController::class, 'index']);

or use this old format so you dont need use

Route::get('/something','App\Http\Controllers\SomeController@index');
Sign up to request clarification or add additional context in comments.

2 Comments

Of course I have done it, there is no problem when I run it locally, but the problem occurs after I deploy my project to hosting.
If it runs locally and not on your server, doublecheck the filename. Pagecontroller.php will work locally, but on most servers only PageController.php will work (case sensitivity)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.