Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

henrylemmon's avatar

404 not found in views subfolders

I have ubuntu server 16.04 loaded on a pc 32bit with - apache2 - mysql Ver 14.14 - php ver 7.2.5 so when I go to 192.168.1.2 in my browser I get the contents of my /var/www/html folder.

I can start a dev server with "php artisan serve --host=192.168.1.2 --port=8000" and plug away at learning laravel. All works fine this way calling controllers from routs/web.php. I have subfolder in resources/views/tasks/index.php and that all works fine with artisan serve.

when I deploy the site to the webserver and dump the contents of the public folder into the /var/www/html folder and change index.php to point back to the rest of the laravel installation in /var/www/blog. then when I type 192.168.1.2 the browser renders welcome.blade.php. which is correct but when I type the 192.168.1.2/tasks I should get the index.php in tasks, but I get a 404 not found.

Please help. Thank You.

0 likes
8 replies
nolros's avatar

@henrylemmon do you have a route for "tasks" in your routes file and do you have a view associated with that route? Suggest you post code for people to review.

henrylemmon's avatar

Yes I have routes set up with controllers and views for each route using illuminate for db. I followed the laracast "Laravel 5.4 From Scratch" course on laravel.com up to the 8th lesson on controllers. then I tried to deploy that on my server. Thank You for your reply.

I can post the code. where should I post it? can I put it in this box?

henrylemmon's avatar

This is the code up to and including the 8th lesson in the laracast "Laravel 5.4 From Scratch"

web.php:

use App\Task;

Route::get('/', function () {

$tasks = Task::all();
return view('welcome', compact('tasks'));
});

Route::get('/tasks', 'TasksController@index');

Route::get('/tasks/{task_id}', 'TasksController@show');

views/welcome.blade.php:

<!doctype html>
<html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>{{config('app.name', 'myblog')}}</title>
    </head>
    <body>
        <ul>
            <?php foreach ($tasks as $task) : ?>
                <li><?php echo $task->body; ?></li>
            <?php endforeach; ?>
        </ul>
        <ul>
            @foreach ($tasks as $task)
                <li>{{ $task->body }}</li>
            @endforeach
        </ul>
    </body>
</html>

views/tasks/index.blade.php:

<!doctype html>
<html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>{{config('app.name', 'myblog')}}</title>
    </head>
    <body>
        <ul>
            <?php foreach ($tasks as $task) : ?>
                <li>
                    <?php echo "<a href=\"/tasks/" . $task->id . "\">" . $task->body . "</a>"; ?>
                </li>
            <?php endforeach; ?>
        </ul>
        <ul>
            @foreach ($tasks as $task)
                <li>
                    <a href="/tasks/{{ $task->id }}">{{ $task->body }}</a>
                </li>
            @endforeach
        </ul>
    </body>
</html>

views/tasks/show.blade.php:

<!doctype html>
<html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>{{config('app.name', 'myblog')}}</title>
    </head>
    <body>
        <p>{{ $task->body }}</p>
    </body>
</html>

controllers/TaskController.php:

<?php

namespace App\Http\Controllers;

use App\Task;

class TasksController extends Controller
{
    public function index() {
        $tasks = Task::all();
        return view('tasks.index', compact('tasks'));
    }
    
    public function show($id) {
        $task = Task::find($id);
        return view('tasks.show', compact('task'));
    }
}

app/Task.php:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Task extends Model
{
    //
}
 

I just want to deploy this on my local server to test. then I can get back to learning laravel. Thanks for your help.

henrylemmon's avatar

I have spent an entire week trying to figure out how to deploy a simple laravel site onto a production server. I have tried every tutorial i could find. Reloaded my server a bunch of times, played with the hosts file and try'd to create a virtual host. I am about to give up and go back to raw php that does not use routs. I think laravel is kool and would like to get involved. Can someone please help me? Thank You. henryLemmon>

henrylemmon's avatar

my public directory is /var/www/html I have the laravel instalation @ /var/www/html/blog php artisan serve --host=192.168.1.2 --port=8000 works great, when I try to use 192.168.1.2 without the aid of artisan serve the routs do not work.

Nash's avatar

when I deploy the site to the webserver and dump the contents of the public folder into the /var/www/html folder and change index.php to point back to the rest of the laravel installation in /var/www/blog

Also, if you have full control over the server, you could have your Laravel installation anywhere you like, e.g. /home/username/my-laravel-project and have a vhost point to Laravel's default public directory. You don't have to move the directories around and change the index file like that (unless you're on shared hosting and have no alternatives).

Please or to participate in this conversation.