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

Frodoe's avatar

Laravel App giving 500 error on DB GET/POST

I'm building a laravel webapp to replace an old website, and I've got the site working on NGINX on an Ubuntu VM. All hardcoded pages load just fine, but on any page with a database connection, I receive a 500 error.

Inspecting the page in Console reports this: GET (URL of Page)..........[HTTP/1.1 500 Internal Server Error 63ms] NGINX access log for the same page load: "GET / HTTP/1.1" 500 1570 "(URL of Page)" No errors reported in the NGINX log.

Permissions seem to be correct, as pages that do load are loading the proper resources from the public directory.

I am using: Laravel 7, PHP 7.4.10, NGINX 1.18.0, MySQL 8.0.22, and Ubuntu 20.04.

Any ideas as to why would be greatly appreciated, i'm quite stumped here.

0 likes
5 replies
jlrdw's avatar

Can you connect to database outside of laravel.

Frodoe's avatar

I have only connected to the database from the command line on the webserver itself

Frodoe's avatar

Created a new user, gave them privileges to the database, and specified that user and password in the .env file

jlrdw's avatar

Created a new user, gave them privileges to the database, and specified that user and password in the .env file

You mean MySql credentials?

Try a simple query in a controller. Of course make a route.

    public function index()
    {
        $users = DB::select('select * from users');

        dd($users);
    }

Make sure you import db:

use Illuminate\Support\Facades\DB;

If the .env is correct you should see results.

Frodoe's avatar

Yes, MySQL credentials, I should have specified. Trying this now, thank you so much

Please or to participate in this conversation.