Skip to content
Start » Laravel » Routing in Laravel doesn't work

Routing in Laravel doesn't work

This article is about routing Laravel not work on new project installations, taking into account a very specific context, new installations of the Apache server.

problem roadmap

At some point you will start a new project with the newly installed project with the framework Laravel, after running the standard command to create a new project with composer:

composer create-project laravel/laravel --prefer-dist

All dependencies downloaded and loaded by composer, permissions set on folders storage and bootstrap/cache, then, to start the work you do the insertion of a test route and a controller for verification, and behold, the error 404 (File not found) is returned.

I went through this problem and started looking for the cause, after verifying that the routes were correct using the artisan on the command line:

php artisan route:list

It is difficult to verify the problem as the route listing is correct. Then comes the self-questioning: I'm doing something very simple wrong, it's not possible that it doesn't work.

Next step, run composer dump to clear cache and redo autoload:

composer dump-autoload

Check the routes again, in addition to making small changes, I tried to access the default route that comes installed to /home, and behold, it also returned the error 404. Very well, indicating that the problem was not my code, but a possible misconfiguration.

Laravel Routing Solution

As I had initially thought, the problem was simple to solve, and I only realized what the cause was after reading this post on Stackoverflow: Laravel routing does not work.

I am working with a new computer, Linux Mint just installed, and I hadn't done all the Apache configurations yet.

So, a possible solution to solve the Laravel routing problem of version 5.x or newer is to first configure url override in Apache, so that the file .htaccess default can work.

To do this, run the command in the terminal

sudo a2enmod rewrite

Then open the configuration file which should be found in the path /etc/apache2/apache2.conf, and find the following code snippet:

Options Indexes FollowSymLinks AllowOverride None Require all granted

Now change the entry AllowOverride None for AllowOverride All.

By doing this you define that all “sites” installed on can perform the overwrite from the root directory /var/www.

Save the file and restart Apache with the command

sudo service apache2 restart

And that's it, routes again working, in short you need to configure Apache so that the .htaccess of your project can overwrite the url.

keep up to date

Don't forget to follow me on twitter and sign the Mazer.dev channel on Youtube to receive updates on new articles, video lessons and free courses in software development and engineering.


More about Laravel

Best Practices for Writing Clean Code
Neste artigo apresento dicas para ao desenvolver um software, escrever com boas práticas de código limpo, o que, em geral, significa escrever blocos de código mais legíveis, em alguns contextos, mais fluídos e, bem estruturados. …
Laravel PHP – Class 'NumberFormatter' Not Found
Ao instalar uma aplicação em um servidor Windows (necessidade de projeto, adequação a infraestrutura do cliente), me deparei com o erro "NumberFormatter Not Found". A primeira reação foi verificar se havia esquecido algum commit de …
How to resolve “COMPOSER_AUTH” does not match the expected JSON schema in Laradock
When using Laradock, accessing the Workspace container, I have sometimes received the second error when trying to run php composer: "COMPOSER_AUTH" does not match the expected JSON schema, this may result in errors and should …
Free e-books on programming and computing in general
Looking for free e-books on programming, software development, and other areas of computing? This list includes these topics as well as books on software engineering and other subjects. The pandemic period has exploded…
How to repopulate with old the input file upload field, in PHP and Laravel
After validating data entry forms, which return to the user with information about the errors that must be corrected, the good practice of populating the fields with the old values (old) is not …
Reasons to choose and use PHP as a programming language
Many beginners and even experienced developers, but who do not know the language, question what are the reasons to choose, and definitely use PHP as the programming language for a small or …

Leave a Reply

Your email address will not be published.

en_USEnglish
%d bloggers like this: