Dimitri
Dimitri

Reputation: 119

Laravel sqlite database does not exist

So recently I deployed my laravel project. But it can't connect to the database. I'm using sqlite and have already created the database.sqlite file(Inside database folder). Local everything works but remote it can't find the file. I have already tried previous solutions such as; Database (database/database.sqlite) does not exist. Database works from artisan tinker

I'm using the default value for the database path see here:

<?php

use Illuminate\Support\Str;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => env('DB_CONNECTION', 'mysql'),

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'database' => env('DB_DATABASE', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'username' => env('DB_USERNAME', 'forge'),
        ],

All my .env variables related to the database are set to null. So it should use the default database_path() function, which it does however the path is not correct because it gives this error: Error message:

Also this is what my env file looks like:

APP_NAME=Laravel
APP_ENV=production
APP_KEY=base64:sKK5gF1A8SsZ1n+MUnBEc760zE9TkAtENbP0arpDtqk=
APP_DEBUG=false
APP_URL=http://admin.dimitrimanen.nl

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=sqlite
#DB_HOST=
#DB_PORT=
#DB_DATABASE=/home/strato/www/di/www.dimitrimanen.nl/htdocs/admin_portal/database/database.sqlite
#DB_USERNAME=
#DB_PASSWORD=

As you can see i also tried the absolute path my server provider noted; https://www.strato.nl/faq/hosting/absolute-paden-en-locaties-van-tools/

Also all my permisions for the folders are set corect as some online solutions sugested, see here: enter image description here

Upvotes: 2

Views: 5515

Answers (3)

DJERAD Abdelheq
DJERAD Abdelheq

Reputation: 1

Open the .env file located in the root of your Laravel project and update the database configuration to use MySQL: The main modification is modifying sqllite to mysql and write the command: php artisan migrate

Upvotes: 0

Mahdi Moazeni Artisan
Mahdi Moazeni Artisan

Reputation: 369

#Create database\database.sqlite

#Go to .env

#Change from

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

#Change to

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=C:/xampp/htdocs/your-project-folder/database/database.sqlite
DB_USERNAME=root
DB_PASSWORD=

Notice! Put the value of DB_DATABASE= according to the database.sqlite address in your project!

#Save changes

#Run under codes in cmd

php artisan optimize:clear

#Then
php artisan migrate
#OR
php artisan migrate:fresh

#It is better to install extension SQLite Viewer on VSCode software.

Upvotes: 1

Dimitri
Dimitri

Reputation: 119

So conclusion don't be a me. The default path has .sqlite at the end but my database was actualy called database.db not sqlite. Atleast i can die in peace now with everything working!

Upvotes: 2

Related Questions