vlehnen's avatar

Laravel can not open SQLite database

Hy, I got a very strange behaviour in my L 5.1 app. I use two databases. One is an MySQL, the other is a SQLIte. If the SQLite file does not exist, is automaticaly created within a provider. The only table inside is also created here. I created a model to access the SQLite. The database file has the owner and group of the httpd.

The strange thing here is, that the app runs on Homestead and on my Ubuntu/NginX box without problems. On the live platform, the SQLite gots created and can be accessed using PHP CLI without any problems, but when Laravel tries to access the database I got the message: 'PDOException' with message 'SQLSTATE[HY000] [14] unable to open database file' in /is/htdocs/wp1112779_D78VPLAD5V/dev/cmadmin/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:50.

The path must be correct, because it is defined in a config file and the provider that creates the database uses this path also.

I got no idea, what is going on there.

0 likes
17 replies
vlehnen's avatar

No effect. As I said, the database was created by Laravel. All access rights are set to the httpd user and group. Laravel must have full access to the database.

bugsysha's avatar

Please check the permissions of the directory that database file is stored in.

vlehnen's avatar

Same, user and group is httpd user. Full access here for Laravel.

vlehnen's avatar

It is a virtual server hosted by another company. I have no chance to restart ;( I just checked another thing. My Laravel provider creates the database file using SQLite Class. I was wondering, if Eloquent will use PDO and if PDO is not correctly installed on the server. So i wrote a small script and I can see, that PDO works. So facts, as far as I can see are:

  1. Laravel has full access to the folder and the database file
  2. Laravel can create the database file using SQLite Class
  3. PDO access to the database is working
  4. The app is running in Homestead and on my Ubuntu NginX Box
  5. The app is not running on the Hosteurope provided virtual server.

I will now try to get support by Hosteurope with a little luck.

vlehnen's avatar

Called the support from Hosteurope - no idea also....

ohffs's avatar

Can you show us an ls -l of the sqlite file and the directory containing it? Possibly also check getfacl database.sqlite . Do you know which OS/distro the hosteurope package is using?

vlehnen's avatar

ls -al

drwxr-x--- 5 wp1112779 wp1112779 127 Oct 12 09:01 .

drwxr-x--- 12 wp1112779 wp1112779 4096 Oct 11 11:03 ..

drwxr-x--- 2 wp1112779 wp1112779 23 Jun 25 11:30 app

drwxr-x--- 5 wp1112779 wp1112779 62 Jun 25 11:30 framework

-rw-r----- 1 wp1112779 wp1112779 25 Aug 26 17:13 .gitignore

drwxr-x--- 2 wp1112779 wp1112779 41 Oct 9 14:32 logs

-rw-r----- 1 wp1112779 wp1112779 2048 Oct 12 08:49 receiptPrinter.sqlite

getfacl receiptPrinter.sqlite

file: receiptPrinter.sqlite

owner: wp1112779

group: wp1112779

user::rw- group::r-- other::---

OS: Debian GNU/Linux 6.0.10 (squeeze)

vlehnen's avatar

Since I ran out of time, I switched to MySQL with success...

umefarooq's avatar

this could be helpful for any body i was also facing same problem, if you are setting database configuration through .env file than need to commented DB_DATABASE config which is null with fresh install of laravel, database config in .env file like this

DB_CONNECTION=sqlite
#DB_HOST=127.0.0.1
#DB_PORT=null
#DB_DATABASE=null
#DB_USERNAME=null
#DB_PASSWORD=null
6 likes
jrean's avatar

sqlite db should be within the database directory (and not storage)

Nullmaruzero's avatar

@jrean — In 5.2 yes, it should be in /database but in earlier versions it was in /storage. This topic is quite old.

@umefarooq —Thanks man! This is just what I needed to know :D Works fine now.

Majid's avatar

This is my database.php file. 'default' => env('DB_CONNECTION', 'sqlite'),

'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'database' => env('DB_DATABASE', database_path('database/storage.sqlite')),
        'prefix' => '',
    ],

and this is my .env file

DB_CONNECTION=sqlite DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=storage DB_USERNAME=homestead DB_PASSWORD=secret and my storage.sqlite file is in database/database/storage.sqlite ,but i'm still getting the same problem. @jrean

Motia's avatar

I got this porblem yesterday and solved it. With some testing, you can verify that sql connection for sqlite uses an URI relative to the public directory, hence,

To solve this set the URI to the database as follows:

        'database' => env('DB_DATABASE/..',  database_path('database/storage.sqlite'))

and the environement vairable DB_DATABASE to:

         DB_DATABASE=database/your_database_name.sqlite

and finally put the database in the database folder.

@Majid

2 likes

Please or to participate in this conversation.