admin管理员组

文章数量:1402857

I have a SQLite database in ./database/database-file.sqlite.

In Laravel, the database is so configured:

// ./config/database.php

return [

    ...

    'connections' => [

        'my-custom-connection' => [
            'driver' => 'sqlite',
            'database' => database_path('database-file.sqlite'),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

...

When I run the app locally, in Docker, all works as expected and database_path() correctly returns the right path to the SQLite file.

However, when I run the app on Heroku, the resulting error is this:

Database file at path [/tmp/build_1032c5ba/database/database-file.sqlite] does not exist. Ensure this is an absolute path to the database.

The problem is that, on Heroku, the base path is identified as /tmp/build_* instead of /app/database/.

Missing storage folder

Different problem, same (?) root cause:

file_put_contents(/tmp/build_1032c5ba/storage/framework/sessions/0OoO2UaEvEqiVygomKADbevSLNSZ7ypiWg9KaLrT): Failed to open stream: No such file or directory

Apart the fact I'm using file sessions (I will change this later: I'm aware of the ephemeral nature of the Heroku's filesystem), the problem is the same: the folder is present and accessible, but, on Heroku, the base path is again /tmp/build_*.

This is obviously wrong, as the correct base path should have been app/storage/....

What I checked

I logged in the dyno and checked the file /app/database/database-file.sqlite actually exists in the folder.

I did the same for the storage folder: it exists and can be accessed.

The problem seems to be the way the base path is identified.

Any ideas about the reason of this mismatching between local Docker and Heroku in identifying the base path?

本文标签: