Search code examples
laravel-5routesapache2ubuntu-16.04restful-architecture

Laravel 5 api route returning 404 apache2


I can't get my api calls to return any data on ubuntu 16.04. Here is my method in routes/api.php:

Route::get('comments', function() {
   // If the Content-Type and Accept headers are set to 'application/json', 
   // this will return a JSON structure. This will be cleaned up later.
   return Comment::all();
});

And this is in RouteServiceProvider:

protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }

When i hit localhost/api/comments I get 404.

I made sure AllowOverride All is set in my site.conf.

My database has a comments table with data that was populated using artisan seed


Solution

  • Turns out I had all of my api calls setup correctly. I could tell because of php artisan route:list being correct. I also had my apache2 sites setup correctly. The problem ended up being I hadn't setup the correct permissions for my base folder.

    Use this command: sudo chmod 755 -R yourprojectbasefolderlocation