-3

I'm getting started to build apps with Laravel framework, by following this video tutorial (in spanish):

https://www.youtube.com/watch?v=A-BL8Ir7puE&list=PLZ2ovOgdI-kWWS9aq8mfUDkJRfYib-SvF&index=2

I'm using:

  • Linux Mint 21 Vanessa

  • Apache/2.4.52 (Ubuntu)

  • PHP 8.2.1

  • Laravel v9.48.0

I have my Laravel project folder located into the directories structure like this:

"/var/www/html/infoalq" ("infoalq" is the name of my project).

So then, the project is located into the default Apache directory, used for placing the content of any website.

My code of "/var/www/html/infoalq/routes/web.php" is this one:

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});


Route::get('principal', function () {
    return 'Bienvenido a InfoAlquiler';
});

The issue is this one: When I open my app by running "php artisan serve" in the terminal, while placed in the project folder (/var/www/html/infoalq/), I can perfectly view the app content in my browser by going to "http://localhost:8000". This shows me, at the moment, the welcome view, since I'm running it just after the Laravel project was created. I can also access the other route setted in "web.php" by going to "http://localhost:8000/principal". At the moment, this path only shows a string with a welcome message, since I'm just testing the routing method.

Then, when I try to open the app by going to "http://localhost/infoalq/public/" (using the 80 HTTP port, just like is configured in Apache by default), it also shows fine the welcome view. However, when I try to open the other route setted in "web.php", by going to "http://localhost/infoalq/public/principal", it shows me a "404 Not Found" error page, instead of the welcome message string. As it's shown in the video, I should be able to see the content of that route, just with entering that last URL in my browser.

I've searched a lot in the web for a similar issue, but I couldn't find any solution.

Does anyone knows if there's any solution for this? Is there any extra information needed? Perhaps I'll need to edit some Apache config files, but I'm really not very acquainted to it.

I've have also another conflict with these two different ways for opening the app, but I think that is better to ask for it in another question.

Thanks a lot!

Leandro

1 Answers1

0

@cengsemihsahin I've searched for enabling mod_rewrite at the web, and I've found this StackOverflow post:

How to enable mod_rewrite for Apache 2.2

In the second answer, I've just got what I needed.

I've done this:

First of all, opened with gedit as sudo the file: "/etc/apache2/apache2.conf"

Somewhere in the file, I had this:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

I've just changed the AllowOverride to 'all', like this:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride all
    Require all granted
</Directory>

Then, after saving changes, restarted Apache with this command:

sudo systemctl restart apache2

After that, the routing worked like a charm!

Thanks a lot both @matiaslauriti and @cengsemihsahin !!