phpjsonlaravellaravel-5.8

Laravel API stopped responding. How to return to service?


Some context: I had a HD failure and had to remove my secondary drive and install it on a new system to get access to my project again. After gaining access i had to setup my environment all over again. I'm running on Windows 10 WSL Ubuntu with Apache2. I believe i have rebuilt all folder and file permission correctly and am now able to run my Laravel API.

sudo chown -R www-data:www-data /path/to/your/laravel/root/directory
sudo usermod -a -G www-data ubuntu
sudo find /path/to/your/laravel/root/directory -type f -exec chmod 644 {} \;  
sudo find /path/to/your/laravel/root/directory -type d -exec chmod 755 {} \;
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

The only catch is none of my API calls work anymore. I get a 404 message. the only route that works is the index route.

I've tried Clearing config/cache/view/sessions etc. and rebuilding the route list but i still get the same 404 error when i try to make an API call.

php artisan cache:clear
php artisan route:cache  
php artisan config:clear 
php artisan view:clear 

I can't even get it to return a simple test message with a test API closure.

<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

    Route::group(['prefix' => '/auth', ['middleware' => 'throttle:20,5']], function () {
        Route::post('/register', 'API\AuthController@register')->name('api.register');
        Route::post('/login', 'API\AuthController@login')->name('api.login');
    });

    // Route::get('/test',function(){
    //     return "Test api";
    // });

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

        Route::apiResources([
            'user' => 'API\UserController',
            'role' => 'API\RoleController',
            'user-role' => 'API\UserRoleController',
        ]);

        Route::post('auth/logout', 'API\AuthController@logout')->name('api.logout');
        Route::get('profile', 'API\UserController@profile')->name('api.profile');
        Route::put('profile', 'API\UserController@updateProfile')->name('api.profile.update');
    });

php artisan route:list results

+--------+-----------+-----------------------------------------+-----------------------------------+---------------------------------------------------------------------------+--------------+
| Domain | Method    | URI                                     | Name                              | Action                                                                    | Middleware   |
+--------+-----------+-----------------------------------------+-----------------------------------+---------------------------------------------------------------------------+--------------+
|        | GET|HEAD  | /                                       | home                              | App\Http\Controllers\HomeController@index                                 | web          |
|        | POST      | api/auth/login                          | api.login                         | App\Http\Controllers\API\AuthController@login                             | api          |
|        | POST      | api/auth/logout                         | api.logout                        | App\Http\Controllers\API\AuthController@logout                            | api,auth:api |
|        | POST      | api/auth/register                       | api.register                      | App\Http\Controllers\API\AuthController@register                          | api          |
|        | PUT       | api/profile                             | api.profile.update                | App\Http\Controllers\API\UserController@updateProfile                     | api,auth:api |
|        | GET|HEAD  | api/profile                             | api.profile                       | App\Http\Controllers\API\UserController@profile                           | api,auth:api |
|        | POST      | api/role                                | role.store                        | App\Http\Controllers\API\RoleController@store                             | api,auth:api |
|        | GET|HEAD  | api/role                                | role.index                        | App\Http\Controllers\API\RoleController@index                             | api,auth:api |
|        | DELETE    | api/role/{role}                         | role.destroy                      | App\Http\Controllers\API\RoleController@destroy                           | api,auth:api |
|        | PUT|PATCH | api/role/{role}                         | role.update                       | App\Http\Controllers\API\RoleController@update                            | api,auth:api |
|        | GET|HEAD  | api/role/{role}                         | role.show                         | App\Http\Controllers\API\RoleController@show                              | api,auth:api |
|        | GET|HEAD  | api/user                                | user.index                        | App\Http\Controllers\API\UserController@index                             | api,auth:api |
|        | POST      | api/user                                | user.store                        | App\Http\Controllers\API\UserController@store                             | api,auth:api |
|        | POST      | api/user-role                           | user-role.store                   | App\Http\Controllers\API\UserRoleController@store                         | api,auth:api |
|        | GET|HEAD  | api/user-role                           | user-role.index                   | App\Http\Controllers\API\UserRoleController@index                         | api,auth:api |
|        | DELETE    | api/user-role/{user_role}               | user-role.destroy                 | App\Http\Controllers\API\UserRoleController@destroy                       | api,auth:api |
|        | PUT|PATCH | api/user-role/{user_role}               | user-role.update                  | App\Http\Controllers\API\UserRoleController@update                        | api,auth:api |
|        | GET|HEAD  | api/user-role/{user_role}               | user-role.show                    | App\Http\Controllers\API\UserRoleController@show                          | api,auth:api |
|        | GET|HEAD  | api/user/{user}                         | user.show                         | App\Http\Controllers\API\UserController@show                              | api,auth:api |
|        | PUT|PATCH | api/user/{user}                         | user.update                       | App\Http\Controllers\API\UserController@update                            | api,auth:api |
|        | DELETE    | api/user/{user}                         | user.destroy                      | App\Http\Controllers\API\UserController@destroy                           | api,auth:api |
|        | GET|HEAD  | oauth/authorize                         | passport.authorizations.authorize | Laravel\Passport\Http\Controllers\AuthorizationController@authorize       | web,auth     |
|        | DELETE    | oauth/authorize                         | passport.authorizations.deny      | Laravel\Passport\Http\Controllers\DenyAuthorizationController@deny        | web,auth     |
|        | POST      | oauth/authorize                         | passport.authorizations.approve   | Laravel\Passport\Http\Controllers\ApproveAuthorizationController@approve  | web,auth     |
|        | GET|HEAD  | oauth/clients                           | passport.clients.index            | Laravel\Passport\Http\Controllers\ClientController@forUser                | web,auth     |
|        | POST      | oauth/clients                           | passport.clients.store            | Laravel\Passport\Http\Controllers\ClientController@store                  | web,auth     |
|        | PUT       | oauth/clients/{client_id}               | passport.clients.update           | Laravel\Passport\Http\Controllers\ClientController@update                 | web,auth     |
|        | DELETE    | oauth/clients/{client_id}               | passport.clients.destroy          | Laravel\Passport\Http\Controllers\ClientController@destroy                | web,auth     |
|        | GET|HEAD  | oauth/personal-access-tokens            | passport.personal.tokens.index    | Laravel\Passport\Http\Controllers\PersonalAccessTokenController@forUser   | web,auth     |
|        | POST      | oauth/personal-access-tokens            | passport.personal.tokens.store    | Laravel\Passport\Http\Controllers\PersonalAccessTokenController@store     | web,auth     |
|        | DELETE    | oauth/personal-access-tokens/{token_id} | passport.personal.tokens.destroy  | Laravel\Passport\Http\Controllers\PersonalAccessTokenController@destroy   | web,auth     |
|        | GET|HEAD  | oauth/scopes                            | passport.scopes.index             | Laravel\Passport\Http\Controllers\ScopeController@all                     | web,auth     |
|        | POST      | oauth/token                             | passport.token                    | Laravel\Passport\Http\Controllers\AccessTokenController@issueToken        | throttle     |
|        | POST      | oauth/token/refresh                     | passport.token.refresh            | Laravel\Passport\Http\Controllers\TransientTokenController@refresh        | web,auth     |
|        | GET|HEAD  | oauth/tokens                            | passport.tokens.index             | Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController@forUser | web,auth     |
|        | DELETE    | oauth/tokens/{token_id}                 | passport.tokens.destroy           | Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController@destroy | web,auth     |
+--------+-----------+-----------------------------------------+-----------------------------------+---------------------------------------------------------------------------+--------------+

Clearly i must be missing something but i have not been able to figure out what. It would be helpful if anyone has any ideas on how i can fix this and save me from having to rebuild my entire project.

Thanks.

Update

As another user asked this is what my apache2.config is set to

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

Solution

  • After the last user posted about my apache config i decided to look at apache's site-available configs

     sudo nano /etc/apache2/sites-available/000-default.conf
    

    I have changed the AllowOverride to all and API calls seem to be working now.

    <Directory  /mnt/d/Dropbox/www/html/public/>
            Options Indexes FollowSymLinks
            AllowOverride all
            Require all granted
    </Directory>
    

    Thanks to @lagbox for leading me to the solution.