8

I'm getting a pretty weird error while trying to deploy a Laravel 5 application to Heroku. If I try to access my root domain https://my-app.herokuapp.com it works fine. However, if I try to access and other domain that is / something aka https://my-app.herokuapp.com/api/v1/users it gives me a 404 not found. Heroku is actually trying to go to the folder /api/v1/users instead of reading the routes file.

here is my Procfile:

web: vendor/bin/heroku-php-nginx public/

now if I try the same thing but with an apache server it works fine:

web: vendor/bin/heroku-php-apache2 public/

ThreeAccents
  • 1,822
  • 2
  • 13
  • 24
  • Did you figure out what's the problem? I also tried deploying a Laravel 4 app with /api resource controller but I am getting an error 404 when accessing other pages than / – schystz Jul 03 '15 at 03:54

4 Answers4

18

https://devcenter.heroku.com/articles/custom-php-settings

Using a custom application level Nginx configuration

Inside the default server level configuration file Heroku uses during the startup of Nginx, it includes a very simple default application level config file. You can replace this file with your custom configuration. For example, to configure Nginx to use some rewrite rules for your Symfony2 application, you’d create a nginx_app.conf inside your application’s root directory with the following contents:

location / {
    # try to serve file directly, fallback to rewrite
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    # rewrite all to app.php
    rewrite ^(.*)$ /app.php/$1 last;
}

location ~ ^/(app|app_dev|config)\.php(/|$) {
    try_files @heroku-fcgi @heroku-fcgi;
    internal;
}

for laravel.

create in root directory nginx_app.conf:

location / {
    # try to serve file directly, fallback to rewrite
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    # rewrite all to app.php
    rewrite ^(.*)$ /index.php/$1 last;
}

location ~ ^/(app|app_dev|config)\.php(/|$) {
    try_files @heroku-fcgi @heroku-fcgi;
    internal;
}

in Procfile:

web: vendor/bin/heroku-php-nginx -C nginx_app.conf /public
Luis Vasquez
  • 428
  • 3
  • 10
1

If you want to use nginx with heroku an laravel you need to add a nginx_app.conf to you public folder and then add this:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

And this is how your Procfile should look:

web: vendor/bin/heroku-php-nginx public/
ThreeAccents
  • 1,822
  • 2
  • 13
  • 24
0

Found a solution on http://laravel.com/docs/4.2/installation#pretty-urls

I has the same problem. Basically, I just added .htaccess file on the /public folder and everything works now.

schystz
  • 800
  • 1
  • 8
  • 21
0

Perhaps you're adding an extra / to your path by accident

Dawit Abraham
  • 1,616
  • 15
  • 19