Laravel: routing not working - php

I have downloaded clients project from the internet, and it is programmed in Laravel (also seen by directory structure). I have set up homestead.yaml, hosts, filled the DB and modified .env. I also did a vagrant provision and 'composer dump-autoload` once everything was done.
Problem I'm facing is that home route '/' returns index.html in root. But route.php says different:
Route::get('/', 'PagesController#home');
Route::get('about', 'PagesController#about');
I've tried to intentionally modify routes so that they point to controller which doesn't exist, deleting some letters inside Kernel.php...anything that would reasonably produce an error, and nothing happens. I still get back what is inside index.html. Also there is index.php which gets returned after I enter anything after slash inside the url:
/bla
/nlo
/xyz
You get the point...what can be the issue?
I have also tried with artisan cache:clear

It's a webserver misconfiguration error. The webserver is configured to serve index.html with more priority than index.php. Relevant configuration can be found at /etc/apache2/httpd.conf, /etc/apache2/sites-available/your-site, .htaccess, or for nginx /etc/nginx/sites-available/your-site just to mention the two most common web servers.

Related

Error 404 after migrating laravel 8 to a shared host

Hello everyone i am new to laravel and i hope someone can help me about my problem. I created a laravel project. After that I import it to cpanel using softaculous. Then, I made some changes base on what i research in the net to avoid showing important file like .env . I created a folder relative to public_html, let say the folder name is 'tamangbilang' where i put almost all of my code except the index.php. Inside my public_html folder, I have another folder named as 'tamangbilang' where my index.php resides. I have followed this instruction https://dev.to/pushpak1300/deploying-laravel7-app-on-shared-hosting-hostinger-31cj the only difference is that I put another folder inside public_html.I also did some changes on the index.php code
require __DIR__.'/../../tamangbilang/vendor/autoload.php';
$app = require_once __DIR__.'/../../tamangbilang/bootstrap/app.php';
Everything is working fine on my login page(my first page) but when I try to login, an error occur.
The requested URL was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
It seems like the connection between routes was lost. I did further testing and I notice that the code is working well only if there is an index.php, before the route in the url. example
http://my-sample-domain.org/tamangbilang/index.php/login
P.S. I don't have access for ssh.
go to bootstrap folder & open cache folder then delete config. after that please check your routes this error basically arises due to routes not found for that go to your project installed on local and write php artisan route: list check if the route is present or not.

Route stopped working

One of my routes is returning this error message:
Not Found
The requested resource /jackpots was not found on this server.
When I change the route name to anything else e.g. route-1, it works.
Server is running on http://127.0.0.1:8000/jackpots via artisan serve
How can I resolve this?
Edit 1:
Does not work:
Route::get('jackpots', 'JackpotsController#getIndex');
Works:
Route::get('jackpot', 'JackpotsController#getIndex');
Turns out the problem had nothing to do with anything in the routes/web.php script.
In my public directory, I also had a folder with the same name as a URL endpoint i.e.
Folder structure
public
|__jackpots
web/routes.php
Route::get('jackpots', 'JackpotsController#getIndex');
This somehow confuses the php server (as well as apache) into thinking you're trying to access the public/jackpots folder whose permissions won't allow you to do that.
I renamed the public/jackpots folder and the problem was resolved.

Route/View related issue in Laravel

I've encountered a problem while creating simple apps with Laravel on IIS.
When I create a new Laravel application I can see the Laravel welcome page just fine.
If I create another view in the same folder as the welcome.blade.php (test.blade.php for example), and set up the route for that in routes/web.php I can't navigate to that page in browser. EDIT: When I attempt this I get a 404.
My web.php is as follows:
<?php
Route::get('/', function (){
return view('welcome');
});
Route::get('/test', function (){
return view('test');
});
At first I thought that perhaps the project was not reading web.php, but when I run php artisan route:list the test route is listed.
I thought perhaps that my view didn't work, so I renamed it as welcome.blade.php and that loaded up fine. I just seem to be unable to add a route to any view or anonymous function that isn't mapped to welcome.blade.php
I tried adding a static route.php file into the app directory with the same code, but that made no difference to the result.
I'm sure I must be missing something basic, but I can't seem to put my finger on where I've gone wrong. Would massively appreciate any help you might be able to offer. Thank you.
Right I worked out where I went wrong. I hadn't run artisan serve. Very simple.
If you're having this problem, try navigating to your application root in cmd and then try
php artisan serve
Then navigate to your page using that information.
Thank you to everyone who posted, massively appreciated.
You need to install Url Rewrite in your terminal. Then import the .htaccess file located in your project/public folder.
To install Url Rewrite, you need to install Web Platform Installer (WPI). Once installed, open WPI then search for the keyword "Url Rewrite", then install the first item in the result. Once the download is finished, Url Rewrite will be available in your IIS Manager
I think IIS server maybe blocks test url.
IIS server has such features.
Before time, I remember that I used IIS blacklist url feature.
You may check IIS url block feature.

Remove server.php from Laravel routes

I just installed laravel following the instruction on Larvel docs. I chose to use install via composer create project command.
In the routes. php i created a dummy route
Route::get('/', function(){
return 'Front Page';
});
When i access http://localhost/mysite/ It shows directory listing of mysite folder. However when i use http://localhost/mysite/server.php It runs my route closure.
I also tried alternate .htaccess code provided at Laravel's docs but that doesn't work either.
I want to remove the server.php from url.
Thanks in advance for help.
This behavior is expected and this is how Laravel works. The public folder is meant for assets and is also (supposed to be) the webservers root directory.
If you are working on localhost that is not the case and the root directory contains multiple projects.
In order to get rid of public you would have to change virtual host settings.
As mentioned here in the site.
The problem with doing virtual hosts is that other projects in localhost will become inaccessible.

Laravel base route errors "NotFoundHttpException"

I'm too newbie to Laravel...I have written this route to echo "Hello World", but It errors NotFoundHttpException
This is my routes.php (no other code is in the file but the following):
Route::get('/', function(){
return "HELLO WORLD";
});
I have also enable mode_rewrite, and also set AlloOverride to 'all' in apache module.
This is also the URL is use to access the page:
http://localhost/laravel/public/mostafa
Do:
php artisan serve
Use that URL to visit your website.
You will see that you get some output like:
Laravel development server started on http://localhost:8000
When you have no clue what Artisan is take a look at this;
http://laravel.com/docs/artisan
Navigate into your project directory with your command prompt and run there the serve command from above.
Example:
Sometimes the default .htaccess file located in public folder doesn't work in apache. Try altering the .htacess as mentioned here. Alternatively renaming your laravel project folder would work especially in XAMPP.
Some other frameworks treat route definitions as relative to the project web root so a path defined as /foo/bar will match http://example.com/additional/levels/laravel/public/foo/bar and will work without changes even if you move the project tree somewhere else in your public web hierarchy. Laravel, however, considers routes as absolute paths so /foo/bar will only match http://example.com/foo/bar.
The simplest solution is probably to move your code into a separate virtual host and point its document root to laravel/public/. (In this case it seems that's actually the intended set-up.)
(I suppose there's a way to make the framework assume an implicit prefix but I've only been using Laravel for 10 minutes.)

Categories