5

I'm try use a sqlite database in my laravel project, in local environment for dev (Windows 8.1 with AMMPS), but when I try run a migrate:instal command, this error apeear:

[PDOException] SQLSTATE[HY000] [14] unable to open database file

My database config file (app/config/local/database.php):

<?php

return array(
    'default' => 'sqlite',

    'connections' => array(
        'sqlite' => array(
            'driver'   => 'sqlite',
            'database' => __DIR__ . '\..\..\database\production.sqlite',
            'prefix'   => '',
        ),
    ),
);
6
  • maybe the database is locked?
    – ori
    May 21, 2015 at 19:28
  • how, if not I'm wearing anywhere? May 21, 2015 at 19:46
  • The final slash in your database path should be a backslash \ instead of a forward slash /. May 21, 2015 at 22:37
  • Yes, but the problem is not that. May 21, 2015 at 22:44
  • Have you tried using an sqlite ide such as SQLite Expert Personal is freeware. That way you will know the db is usable. May 21, 2015 at 23:03

10 Answers 10

19

try to remove the DB_DATABASE="yourdatabase" variable in your .env file

1
  • 1
    @JakubKopyś Because the .env file's values are loaded from config/database.php as long as the keys are listed inside, no matter what their value is. If a key is not found in the .env file, it defaults to the value set in config/database.php, which would be .../database/database.sqlite in the case of DB_DATABASE (as of Laravel 5.3) Oct 24, 2016 at 15:29
4

If the permissions allow to write on the folder just create the storage folders.

e-g, this how I fix the problem.

in config/database.php :

'connections' => [

  'sqlite' => [
      'driver'   => 'sqlite',
      'database' => storage_path('database/databaseName.sqlite'),
      'prefix'   => '',
  ],

Then if you run on your terminal php artisan migrate, it returns you the [PDOException] SQLSTATE[HY000] [14] unable to open database file

Create the path folder by your own, e-g in your terminal mkdir storage/database/databaseName.sqlite

Make sure the permissions allow you to write, then re-run the command php artisan migrate, it returns you the success message : Migration table created successfully.

2

On laravel 5.3.x

This was the only thing that worked for me:

Change DB_CONNECTION from "mysql" to "sqlite". Because this is an sqlite database, you can delete all the other DB_* items in that .env file.

APP_ENV=local APP_KEY=base64: APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://localhost

DB_CONNECTION=sqlite

2

You just need to make sqlite file available at the defined path. In larvel 5.7, I just used following command and run migration.

touch /absolute/path/of/db.sqlite

That will create an empty file at defined location and you are good to go.

Observation: In Larvel 5.7, .sqlite file should be already available at defined location.

For windows, right click and create new file with the defined name at defined location.

1

try change the file databaseName.sqlite permission database to writeable and readable. Maybe change permissions folder database also.

In the production server change this file database to private directory for security.

0
1

Well it may be late but I have also faced the problem in ubuntu environment, here exactly how I overcome this issue.

You have to pass your fully qualified sqlite file's path to your .env file, like following:

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="/var/www/html/my-awesome-project/database/database.sqlite"
DB_USERNAME=homestead
DB_PASSWORD=secret

Here change the value of DB_DATABASE key to the exact location of your sqlite file in your computer's filesystem.

Tips: You can find your database's path for sqlite file by adding

dd(database_path('database.sqlite'));

this line of code in the top of config/database.php file and run php artisan migrate to terminal. You can find the exact location from there, copy it and put it to .envs DB_DATABASE key.

Don't forget to restart laravel server and remove dd(database_path('database.sqlite')); form database.php before testing.

0

In my case, changing url: '%env(DATABASE_AUTH_URL)%' to url: '%env(resolve:AUTH_DATABASE_URL)%' fixed the issue

0

At al most , You have to set the right path to your SQLite database file.

To mitigate the conflict between settings in .env file and database.php file in config folder, Just set database file path in database.php file and remove it from .env file. .env file just write your connection and remove other database attributes.

DB_CONNECTION=sqlite

second open config/database.php go to connections array and change database path to your database file path database_path('your database file path')

'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'url' => env('DATABASE_URL'),
        'database' => database_path('mydb.sqlite'),
        'prefix' => '',
        'foreign_key_constraints' => env('DB_FOREIGN_KEYS', false),
    ],
-2

Please check the permissions of the directory that database file is stored in. chmod 777 YOU_APP/database

-3

Change DB_CONNECTION from "mysql" to "sqlite". Because this is an sqlite database, you can delete all the other DB_* items in that .env file.

APP_ENV=local
APP_KEY=base64:
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=sqlite

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.