This article deals with the Laravel routing not to working in new projects, taking into account a very specific context, when you have new Apache server installations.
At some point you will start a new project with the newly installed project with the Laravel Framework, after running the standard command to create a new composer project:
composer create-project laravel/laravel <nome-do-projeto> --prefer-dist
All dependencies downloaded and loaded by the compose, hosted permissions on the
bootstrap/cache folders, so to start the work you enter a test route and a checking controller, and here’s 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 artisan on the command line:
php artisan route:list
It is difficult to check the problem because the list of route is correct. Then comes the self-questioning: I am wrong something very simple, it is not possible that it does not work.
Next step, run the composer dump to clean cache and redo the composer autoload:
Check the routes again, in addition to making minor changes, I tried to access the default route that is installed to
/home, and behold it also returned the error 404. Very well, indicative that the problem was not my code but a possiblepoorly made configuration.
Solution for Laravel Routing
As I had initially thought, the problem was simple to solve, and I only realized what was the cause after reading this post at Stackoverflow: Laravel routing does not working.
I am working with a new computer, Linux Mint newly installed, and had not yet done all Apache settings.
So a possible solution to solve the Laravel 5.x or more current versioning problem is first to configure the URL overpacking on Apache so that the standard
.htaccess file can work.
To do this execute the command at the terminal
sudo a2enmod rewrite
Then open the configuration file that should be found on the way
/etc/apache2/apache2.conf, and find the following code passage:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
Now change the input
AllowOverride None to
By doing this you define that all the “sites” installed in can perform the override from the root directory /var/www.
Save the file and restart the apache with the command
sudo service apache2 restart
And that’s it, routes again working, in summary, you need to configure Apache so that the
.htaccessof your project can do the URL rewrite.