jadjoubran / laravel5-angular-material-starter

Get started with Laravel 5.3 and AngularJS (material)
https://laravel-angular.readme.io/
MIT License
1.66k stars 401 forks source link

Deploying project from Windows Local environment to ubuntu 16.04 production environment on AWS #486

Closed DedSec49 closed 7 years ago

DedSec49 commented 7 years ago

Error that I am getting: ' Not Found

The requested URL /api/game was not found on this server.

Apache/2.4.18 (Ubuntu) Server at xx.xxx.xxx.xxx Port 80 '

On Chrome console the error is GET http://xx.xxx.xxx.xxx/api/game 404 (Not Found) in file >>final-e7d94059db.js:12433<<

File: >>api.php Route::get('game', 'game@getData');

File: >>game.php

`<?php namespace App\Http\Controllers; use Illuminate\Support\Facades\DB; use Illuminate\Http\Request; class game extends Controller { public function getData(){

    $playArea = DB::table('objects_table')->get();
    return json_encode($playArea);

}

}'

File: >>gamePage2.component.js

'constructor(API, $localStorage){ 'ngInject'; // super(); this.APi=API; }

$onInit(){

    this.APi.all('game').get('').then((response) => {
        this.objectsData=response;
        this.localS.res=response;
        this.initObjectData(this.objectsData);
    });

}`

jadjoubran commented 7 years ago

Hi @DedSec49 Unfortunately this depends on numerous configuration files I'd say, make sure you pointed your webserver to the public/ directory Also make sure to read the log file for apache to understand why it's returning 404

DedSec49 commented 7 years ago

Hi! I already pointed my webserver .conf to the public folder my normal site is running fine but its only the case with the API. Its showing 404, its just not calling the database. I also checked my .env file and everything is fine and updated there. Main error is :

'/#!/game/game2:1 Uncaught (in promise) DOMException: Only secure origins are allowed (see: https://goo.gl/Y0ZkNV). final-e7d94059db.js:12433 GET http://xx.xxx.xxx.xxx/api/game 404 (Not Found) (anonymous) @ final-e7d94059db.js:12433 sendReq @ final-e7d94059db.js:12178 serverRequest @ final-e7d94059db.js:11930 processQueue @ final-e7d94059db.js:16689 (anonymous) @ final-e7d94059db.js:16733 $eval @ final-e7d94059db.js:18017 $digest @ final-e7d94059db.js:17827 $apply @ final-e7d94059db.js:18125 done @ final-e7d94059db.js:12233 completeRequest @ final-e7d94059db.js:12459 requestLoaded @ final-e7d94059db.js:12387 '

jadjoubran commented 7 years ago

Have you tried using https? As the error message says: only secure origins are allowed

DedSec49 commented 7 years ago

Yup. Not working

DedSec49 commented 7 years ago

It only the API thats not working rest everything is working perfectly fine Moreover HTTPS problem thats a another issue.

DedSec49 commented 7 years ago

Here's something more:

Possibly unhandled rejection: {"data":"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p>The requested URL /api/game was not found on this server.</p>\n<hr>\n<address>Apache/2.4.18 (Ubuntu) Server at xx.xxx.xxx.xxx Port 80</address>\n</body></html>\n","status":404,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","headers":{"Accept":"application/x.laravel.v1+json","X-XSRF-TOKEN":"eyJpdiI6InJUbEdWSlBPZlpHMnlBNUNGc1JZWlE9PSIsInZhbHVlIjoiOUEyUndhN0EyWVlPQTBvdnVxeGRkTVwvbmhIdFhpZEtHR3l5aldTUW43Y21rSzlMQVZ6R3Q1aGZsTXM3TE5iU0JzZVFaNHdoWlFaMlV2QjgrY1BSN2RBPT0iLCJtYWMiOiI5YTdlOGZkZDAxNWRhNTRjN2YxYmI3ODQ2ZjRiYTcxNmQyN2UxNWU5MWQ0YWI2N2NjYmNjOTE0Yjg3MTYwYjQ3In0="},"url":"/api/game","cached":false},"statusText":"Not Found"}

tarkant commented 7 years ago

Hello there, my reply might be late and you might already have solved your issue but if someone encounters this problem I might have the explanation. We've deployed a project made with this boilerplate (a great shoutout for this amazing project) and we were not able to access to the /api routes or any other route. All we had was 404 Not Found error thrown by Apache 2.4 and the error was not logged because for Apache, that was not a problem. If you've installed a clean environnement and created a virtual host for your Website, you might have forgotten to tell Apache to allow the .htaccess files to override the rewrite rules of Apache. To do so, you'll have to go to your apache configuration file located usually in /etc/apache2/sites-available/000-default.conf or /etc/apache2/your-vhost_com.conf and add this rule to the bottom of the file : <Directory /var/www/your-vhost_com/public> Allowoverride All </Directory> After applying this config, you have to restart the apache2 service : service apache2 restart And if you've setup everything well, you'll have your redirects working.

More notes:

I hope it helps!

DedSec49 commented 7 years ago

Thanks tarkant. The only problem with me was because of the command:

sudo a2enmod rewrite

Now error is solved and API is working fine.