PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Question By
Solved

API works for localhost but gives 500 error for live website

Solved
alexmorning

Jan 17th, 2023 02:11 AM

I'm not sure if there's anything I need to do that would allow this to work, but based on docs and videos, it seems like this should work out of the box (and the fact that it works fine on localhost site also tells me this).

When I do this in Insomnia, I get the 500 error with the same styling that you get on a server error when you browse normally and do something that doesn't work. I've enabled debugging via app.php, because that's what i've seen suggested by a lot of people with similar issues. I did so with these 2 commands, I wasn't sure which was correct because I've seen both suggested.

'debug' => (bool) env('APP_DEBUG', true),
'debug' => env('APP_DEBUG', true),

Either way, I still don't get any debug messages showing up. This is my first time using PHP, Laravel, or anything other than HTML/CSS/JS, so I am trying to learn a lot, but am I correct to assume that my .env file is only used on my localhost site? If so, it seemed weird that I've seen quite a few times on here/wave-pro repo where it was suggested that they turn on app_debug in their .env file, because I just assumed that at least some of those people were debugging a live website error. Or is it just assumed that 99% of the errors you solve for your local environment will also fix the problem in a live environment? Sorry, just trying to get clarification, because it looked like the .env file was totally ignored when launching to Digital Ocean.

I checked the logs in Digital Ocean but there was nothing helpful, it just showed the API attempt with the 500 error and that's really it. Laravel logs showed nothing about this whatsoever, from what I could tell.

Thanks so much

bobbyiliev

Jan 17th, 2023 05:57 AM

Best Answer

Hi there,

With the DigitalOcean App Platform, you don't define your environment variables in a .env file but you use their environment variables functionality:

How to Use Environment Variables in App Platform

If you've deployed your app on a standard server, that it would use a .env file.

Enabling the debug only would mean that your errors will be logged into the storage/logs/laravel.log file, so you can open the console and check the contents of the file with tail -100 storage/logs/laravel.log.

If you want to display the errors on the site directly, then you can change the APP_ENV variable from production to local for example.

For the API, you most likely need to specify the JWT_SECRET variable in order for it to work. It sounds like that you have it already defined in your local env but not on your DigitalOcean server.

Let me know how it goes.