Francis Kisiara
Francis Kisiara

Reputation: 325

Requested URL was not found on this server while running a laravel application

I am facing an issue with deploying my Laravel 5.3 application.

I get an error saying my route was not found on the server. Surprisingly, i am able to get to the welcome page without a problem but if I try to click on the registration button or any other route, I get this error.

I'm using a linux 16.04 server on digital ocean and everything is working fine on localhost. I have tries multiple solutions but nothing seems to work. Any help is much appreciated.

My Routes File

Auth::routes();

Route::get('/', function () {
    return view('login');
})->name('login');

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

Route::get('auth/{provider}', 'Auth\RegisterController@redirectToProvider')->name('auth');
Route::get('auth/{provider}/callback', 'Auth\RegisterController@handleProviderCallback');

Route::group(['middleware' => ['auth']], function(){

    //Tasks
    Route::get('/task', 'TaskController@index');
    Route::get('/task/{taskId}/{notification?}', 'TaskController@view');
    Route::get('/create-task', 'TaskController@create');
    Route::get('/close-task/{taskId}', 'TaskController@finaliseTask');
    Route::post('/reinitialise-task/{taskId}', 'TaskController@reinitialiseTask');

    Route::post('/task', 'TaskController@store');
    Route::post('/task/comment/{taskId}', 'TaskController@postTaskComment');

    //Reports
    Route::get('/reports', 'ReportsController@view');
    Route::get('/create-report/task/{taskId?}', 'ReportsController@generateReport');

    //Settings  
    Route::get('/settings', 'SettingsController@index');
    Route::post('/category', 'SettingsController@storeTaskCategory');

});

I am able to access the login route but cant access any other.

I have setup my virtual host as shown below.

<VirtualHost *:80>

ServerAdmin [email protected]
ServerName mydomain.name.com
ServerAlias www.mydomain.name.com
DocumentRoot /var/wwww/html/public
ErrorLod ${APACHE_LOG_DIR}/error.log
CustomLog ${Apache_LOG_DIR}/access.log combined

<VirtualHost>

I also would love a solution that doesn't force me to move files around as doing so end up breaking composer and artisan.

Upvotes: 0

Views: 1974

Answers (1)

Jeremy Harris
Jeremy Harris

Reputation: 24549

For your .htaccess to take over and handle routing through Laravel, you need to tell your vhost to allow it's config to be overridden (by the .htaccess file).

<VirtualHost *:80>

    ServerName mysite.com
    DocumentRoot "/var/www/mysite/public"

    <Directory "/var/www/mysite/public">

        Options Indexes FollowSymlinks MultiViews
        AllowOverride All
        Require all granted

        # ADD THIS IF USING PHP-FPM
        <FilesMatch "\.php$">
            Require all granted
            SetHandler proxy:fcgi://127.0.0.1:9000
        </FilesMatch>

    </Directory>

</VirtualHost>

The AllowOverride All value tells Apache that it is ok for the application to modify the vhost config.

If you don't see mod_rewrite in the output of apachectl -M, you need to enable it:

sudo a2enmod rewrite

Make sure after making any of these changes that you reload Apache:

sudo service apache2 reload

Upvotes: 1

Related Questions