SQLite无法打开数据库文件:Laravel + Windows

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'   => '',
        ),
    ),
);

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.

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

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

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

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.

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.

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

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.