Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

moshie's avatar

Laravel 5.1 / Forge Cors 404/phpinfo

I am using laravel-cors

when I attempt to access my api cross origin I get the phpinfo() ?

my app is hosted on staging.domain.io and my api is hosted on api.domain.io/v1

My code works on my local machine but when pushed to the staging domain the api loads up the phpinfo

I am hosting with digital ocean and using forge to setup the sites.

Sites I have setup are:

  • staging.domain.io
  • domain.io
  • api.domain.io

If I remove api.domain.io from the list of sites the api returns an nginx 404 error :/

I have included my route service provider code below in hope it might help :S :

// Enviroment Var
APP_DOMAIN=domain.io
// Route provider
protected $endpoints = ['Core', 'Auth'];
foreach ($this->endpoints as $endpoint) {
    $router->group([
        'namespace' => 'Unite\Api\\' . $endpoint . '\Controllers',
        'prefix' => 'v1', 'middleware' => 'cors',
        'domain' => 'api.' . env('APP_DOMAIN', 'localhost') ], 
        function ($router) use ($endpoint) {
                $route = $endpoint == 'Core' ? '/' : $endpoint . '/';
                require app_path('Api/' . $route . 'routes.php');
    });
}

Routes:

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

Any help would be great!

0 likes
3 replies
michaeldyrynda's avatar

Where do you have api.domain.io configured to point? Is it at the same folder / location as domain.io, or have you deployed two separate instances of the application?

You get the phpinfo page by default on a Forge site if it's just been configured, so chances are api.domain.io is pointing to /home/forge/api.domain.io/public, whilst domain.io is pointing to /home/forge/domain.io/public.

2 likes
chrisgeary92's avatar
Level 13

How is your forge setup? .. Your api.domain.io shouldn't be it's own website/install on the server. You should have 2 sites on your server for:

  • staging.domain.io
  • domain.io

Each of these could be setup to support wildcard subdomains (or just add api.) for each to the configuration on forge. Then if you access:

  • api.staging.domain.io
  • api.domain.io

These will both work, and will direct you to your laravel installation. Currently it looks like your api. domain is setup as it's own site in forge, so it's not looking at your laravel installation.

Hope that makes sense? :)

1 like

Please or to participate in this conversation.