TomCoke's avatar

Different driver locally vs production

I'm completely new to Laravel.

I want to use sqlite in my local environment and mysql on production. How do I do that?

I cannot run my migrations if I remove the "default" in database.php where I also set up the array with "local" and "production" under "connections" with the appropriate driver.

Thanks!

0 likes
6 replies
click's avatar

I would not recommend this. Keep your production and local development environment as equal as possible. Is there a specific reason you want to do this?

But if you still want to do it, can't you do this with an ENV setting?

# config/database.php
'default' => env('DB_CONNECTION', 'mysql'),

and than on in your local .env file.

DB_CONNECTION=sqlite 

And production:

DB_CONNECTION=mysql 

where sqlite & mysql are the names of your connection.

audunru's avatar

Put different values in the .env file on your computer and the production server. Thats what its for. And if you do this, you need some way to check your migrations etc against something more realistic before you deploy to prod.

TomCoke's avatar

Seems to work partially - the migrations ran.

However, when I head over to the website it says "Database [sqlite] not configured.". Any ideas?

This is my database.php

                'local' => array(
                        'driver'   => 'sqlite',
                        'database' => __DIR__.'/../database/database.sqlite',
                        'prefix'   => '',
                ),

                'production' => array(
                        'driver'    => 'mysql',
                ),

                'testing' => array(
                    'driver'    => 'mysql',
                ),

My .env says

APP_ENV=local
...
DB_CONNECTION=local
Snapey's avatar

Hi

You should not have need to change the database.php file.

Just indicate in the .env file, which connection you want to use, not which environment.

If you make changes to config, remember to run php artisan config:clear or re-cache with php artisan config:cache

siangboon's avatar

did you create your database/database.sqlite file and create the database accordingly? As all said, you really need not make any change on database.php file but just update the .env database value for different environment will do.

Please or to participate in this conversation.