0

Using Laravel Framework version 5.2.31 and Apache/2.4.12 (Ubuntu) Server. Got following error message:

404 Not Found The requested URL /laravel/public/signup was not found on this server.

Thank you for any help.

Below is routes.php (That file is no longer accurate. See new one below in Edit section)

<?php

Route::group(['middleware' => ['web']], function() 
{
    Route::get('/', function () 
    {
        return view('welcome');
    });
    Route::post('/signup', [
        'uses' => 'UserController@postSignUp',
        'as' => 'signup'
    ]);
});

Below is UserController.php file

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function postSignUp(Request $Request)
    {
        $email = $request['email'];
        $prenom = $request['prenom'];
        $motDePasse = bcrypt($request['motDePasse']);

        $user = new User();
        $user->email = $email;
        $user->prenom = $prenom;
        $user->motDePasse = $motDePasse;

        $user->save();

        return redirect()->back();
    }

    public function postSignIn(Request $Request)
    {

    }
}

Edit

Below is routes.php

<?php

Route::get('/', function () 
{
    return view('welcome');
});
Route::post('/signup', [
    'uses' => 'UserController@postSignUp',
    'as' => 'signup'
]);

Below is RouteServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @param  \Illuminate\Routing\Router  $router
     * @return void
     */
    public function boot(Router $router)
    {
        //

        parent::boot($router);
    }

    /**
     * Define the routes for the application.
     *
     * @param  \Illuminate\Routing\Router  $router
     * @return void
     */
    public function map(Router $router)
    {
        $this->mapWebRoutes($router);

        //
    }

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @param  \Illuminate\Routing\Router  $router
     * @return void
     */
    protected function mapWebRoutes(Router $router)
    {
        $router->group([
            'namespace' => $this->namespace, 'middleware' => 'web',
        ], function ($router) {
            require app_path('Http/routes.php');
        });
    }
}

2 Answers2

1

First, it seems like you're using post method in routes.php, but you're trying to load the route using get method.

Second this is you have wrong web server configuration. Web server should be pointed to a public directory of you Laravel project (you should create VirtualHost for it and restart web server).

Also, remove web middleware from routes.php, becuase it will cause errors.

Community
  • 1
  • 1
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
  • I've edited file `route.php` according the links you have provided. I checked file `RouteServiceProvider.php` on my server; its content is the same as the one one here [link]https://github.com/laravel/laravel/commit/5c30c98db96459b4cc878d085490e4677b0b67ed#diff-b467cc786635bd6945b17726282f1c64[/link] The error message `404 page not found` still showing. – user5293879 May 15 '16 at 21:38
  • Did you do other two things from my answer? – Alexey Mezenin May 16 '16 at 00:56
0

Add this to the .htaccess

RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

And change paths for :

open local/bootstrap/paths.php

'public' => __DIR__.'/../public', to 'public' => __DIR__.'/../../',

open local/bootstrap/paths.php and find below code

'public' => DIR.'/../public', change with below code

'public' => DIR.'/../../',

Open index.php (on root) and find below code

require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';

change with below code

require __DIR__.'/local/bootstrap/autoload.php';
$app = require_once __DIR__.'/local/bootstrap/start.php';

Now you have all set you can access url http://example.com/ if still problem try with clear cache of browser.

Murlidhar Fichadia
  • 2,589
  • 6
  • 43
  • 93
  • I'm using Apache/2.4.12. That line is already uncommented in `/etc/apache2/mods-enabled` as `LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so` – user5293879 May 15 '16 at 21:16