5

I've a Laravel5/angularJS app (beeing Laravel as an api rest and angular for the front-end)

At my local environment everything works like charm.

But when i upload to a hosting i can only access to the index page, everything else throws a 404.

in my shared hosting i have the file-system like this.

public_html
    laravel-backend (it has app, bootstrap, confi...etc, all laravel app)
    laravel-frontend (it would be like the public folder of the laravel default file system)
    .htaccess

the .htaccess content:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP_HOST} anotherAppDomainAtSharedServer$ [NC]
    RewriteCond %{REQUEST_URI} !/.*$
    RewriteRule ^(.*)$ /$1 [L]

    RewriteCond %{HTTP_HOST} laravelAppDomain$ [NC]
    RewriteCond %{REQUEST_URI} !^/laravel-frontend/.*$
    RewriteRule ^(.*)$ /laravel-frontend/$1 [L]

</IfModule>

index.php inside laravel-frontend:

require __DIR__.'/../laravel-backend/bootstrap/autoload.php';
$app = require_once __DIR__.'/../laravel-backend/bootstrap/app.php';


$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

and the routes.php

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

Route::group(['prefix' => 'api/v1'], function(){
    Route::resource('authenticate', 'AuthenticateController', ['only' => ['index']]);
    Route::post('authenticate', 'AuthenticateController@authenticate');
    ....

So, as i said, i can see login page, but when i want to login i get 404 error

http://laravelAppDomain/laravel-backend/api/v1/authenticate 404 (Not Found)
NotFoundHttpException in RouteCollection.php line 161:

any clue? any configuration i miss?

In addition, i have not access to configuration server, i mind i can't edit etc folder hosts, vhosts or similar like i did in my local environment.

Padron Leandro
  • 313
  • 1
  • 4
  • 16

2 Answers2

6

Assuming you're on an apache2 server on Unix:

  • run the command sudo a2enmod rewrite
  • make sure that there's a section of your /etc/apache2/sites-available/000-default.conf that looks like the following. Note that /var/www/html is the root directory default of apache2, yours may be /var/www/html/public or something to that effect.

    <Directory /var/www/html> AllowOverride All </Directory>

  • run sudo service apache2 restart

  • see if that works.
dargue3
  • 2,802
  • 2
  • 14
  • 23
2

I'm not sure how, if someone can give me a theorical answer is welcome.

I changed the folder structure:

public_html
    laravel-app
        public

the standar laravel way.

then I configure the .htaccess pointing to the public and the request became to work.

Padron Leandro
  • 313
  • 1
  • 4
  • 16
  • 1
    But it's a bad idea to have your full `laravel-app` available within the web-server's publicly-viewable directory structure. See this article as to some suggestions... (https://laravel-news.com/subfolder-install) – Phil Ryan Jun 19 '19 at 07:30