I migrated my local laravel 5 project onto my AWS ec2 lamp Ubuntu server.
http://realtoraxe.com/realtoraxe/public/ but it shows
InvalidArgumentException in SQLiteConnector.php line 34: Database does not exist.
I changed the database.php set for sqlite
<?php
return array(
'default' => 'sqlite',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => 'http://realtoraxe.com/realtoraxe/storage/database.sqlite',
'prefix' => '',
),
),
);
?>
and I changed the .env to
APP_ENV=local
APP_DEBUG=true
APP_KEY=mystring
DB_CONNECTION=sqlite
CACHE_DRIVER=file
SESSION_DRIVER=file
it still doesn't see the database
Laravel probably does not support much of the helper functions( e.g. storage_path) inside config files, but it surely does supports env function. More info here
That's the reason it's unable to locate your database. You should define the database in .env file or use the full path in the config file instead.
Related
I want to use the sqlite db stored in "C:\Folder\my_database.sqlite" , what should i do? I want to use that sqlite db. Can anyone please suggest me a solution?
So i can give the path to sqlite in database.php below:
'sqlite' => [
'driver' => 'sqlite',
'database' => "path to my sqlite db",
'prefix' => '',
],
Also if that is done, then i can change my default connection to sqlite. Like:
DB::setDefaultConnection('sqlite');
Can anyone please suggest me a solution?
As the Laravel Documentation states:
After creating a new SQLite database using a command such as touch
database/database.sqlite, you can easily configure your environment
variables to point to this newly created database by using the
database's absolute path:
'sqlite' => [
'driver' => 'sqlite',
'database' => "C:\Folder\my_database.sqlite",
'prefix' => '',
],
To make it the default connection, just set this in your .env file:
DB_CONNECTION=sqlite
Open your .env file and set,
DB_CONNECTION=sqlite
DB_DATABASE=C:\Folder\my_database.sqlite
further more information you can see: https://laravel.com/docs/5.7/database
for set sqlite database you can add absoulate path like this in database.php file..
'sqlite' => [
'driver' => 'sqlite',
'database' => 'C:\Folder\my_database.sqlite',
'prefix' => '',
],
for set a default sqlite connection update this in your .env file:
DB_CONNECTION=sqlite
for production update line(number 16) in database.php
'default' => env('DB_CONNECTION', 'sqlite'),
and then run this command in terminal for remove old configration and create new configration file.
php artisan config:cache
EDIT : Thanks to #PedroFaria99, clear config cache solved the problem, but if anybody want to bring an explanation about the randomness aspect feel free.
I have an issue with my laravel 5.5 local installation (production environnement isn't impacted). Here Laravel is used as an API and serves a client-sided VueJS application.
Sometimes (randomly), my laravel is returning 500 error to my client. It can happens on various routes, never the same one, after 1 to 10 successives HTTP request or not and when I check the storage
[2018-03-09 13:44:08] production.ERROR: PDOException: SQLSTATE[HY000] [1045] Access Denied for user: 'forge'#'#localhost' (password: NO) in [...] Illuminate\Database\Connectors\Connector.php:119
However, my .env file is settup, and my database.php is using env() with default parameters are "forge" and "localhost". So I tried to change this parameter to "test", and the next 500 errors was same but with "test" instead of "forge".
I'm very confused, since this error doesn't happen systematicly.
.env file
APP_ENV=local
APP_DEBUG=true
DB_HOST=localhost
DB_DATABASE=mydatabase
DB_USERNAME=root
DB_PASSWORD=
database.php
...
'default' => env('DB_CONNECTION', 'mysql'),
...
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'test'),
'username' => env('DB_USERNAME', 'test'),
'password' => env('DB_PASSWORD', '')
...
Try
php artisan cache:clear
php artisan config:cache
It happens because laravel saves env values in its cache and if your config is not cached it will take the configuaration that are saved in the database.php file. You can not directly access env values on runtime.
I hate to revive a dead thread but after some soul searching I found the issue might just be php's lack of thread safety : https://github.com/laravel/framework/issues/28571 and the great writeup here : https://mattallan.me/posts/how-php-environment-variables-actually-work/
I have this situation in laravel 5.2 where if I do this:
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=
DB_DATABASE=database/database.sqlite
DB_USERNAME=
DB_PASSWORD=
in the .env file I get this:
InvalidArgumentException in SQLiteConnector.php line 34:
Database (database/database.sqlite) does not exist.
on trying to manipulate the laravel error rendering system with this code from a controller:
<?php
namespace App\Http\Controllers;
use App\User;
class SampleController extends Controller
{
public function findUser()
{
$user = User::firstOrFail();
return $user->toArray();
}
}
And this goes well with php artisan migrate command, but to get the controller code to render the error as expected I have to do this:
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=
DB_DATABASE=../database/database.sqlite
DB_USERNAME=
DB_PASSWORD=
To fix the problem so I get both php artisan migrate and SampleController to work I have put this in the config/database.php file:
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
Why is the default means to access sqlite as given on the laravel website not working. Is it a bug I should be aware of?
The normal configuration in the config.php file is expected to be
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
Furthermore, the appropriate way to mention the DB_DATABASE in the .env file is to specify the absolute file name, such as /var/www/laravel/database/database.sqlite not the relative location.
For example, in Windows
DB_DATABASE=C:\wamp\www\laravel\database\database.sqlite
And this is what is mentioned in the Laravel Documentation
DB_DATABASE=/absolute/path/to/database.sqlite
I'm trying to get started with Laravel + PostgreSQL and been following the database tutorial.
Unfortunately, after updating the database configuration file and running php artisan migrate, the following error appears:
[InvalidArgumentException]
Database [postgres] not configured.
What puzzles me is that I didn't specify the "postgres" database in the configuration, but another database I set through cPanel, say "example_database".
Here's some relevant parts of my /config/database.php configuration:
'default' => env('DB_CONNECTION', 'postgres')
And inside the connections array of the same file:
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'example_database'), // This seems to be ignored
'username' => env('DB_USERNAME', 'example_username'),
'password' => env('DB_PASSWORD', 'example_password'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public'
],
The actual database credentials I'm using are working perfectly on my SQL Workbench client, so this seems to be a Laravel config problem. Any ideas? I have searched around for at least an hour to no avail.
You have to enter your configuration in the .env file.
The configuration you made will only be loaded if they are not already defined in .env
You need to use pgsql instead of postgres.
DB_CONNECTION=pgsql
DB_HOST=localhost
DB_DATABASE=DB_NAME
DB_USERNAME=USER
DB_PASSWORD=PW
Laravel sometimes caches your configurations. If you run into this problem while everything looks alright try running
php artisan config:cache
I know this is an old question and it already has an answer; however, here is an small explanation why:
If you check your database.php in the config directory, you will see that you have few connections types, including pgsql. So, the key have to match to the DB_CONNECTION in .env file. You can definitely replace pqsql connection key with postgres, and it will work on the same way.
However, I would recommend replacing the value DB_CONNECTION, instead of modifying the config.
DB_CONNECTION=pgsql
My app/config/database.php has been setup like this:
'mysql' => array(
'driver' => 'mysql',
'host' => getenv('DB_HOST'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USER'),
'password' => getenv('DB_PASS'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I have updated my env detection code like this in bootstrap/start.php:
$env = $app->detectEnvironment(function() {
return file_exists(dirname(__FILE__) . '/../.env.production.php')
?
'production'
:
'local';
});
Now, I have uploaded .env.production.php with the following:
<?php
return
[
'DB_HOST' => '178.xxx.xxx.xxx',
'DB_NAME' => 'USERNAME',
'DB_USER' => 'PASSWORD',
'DB_PASS' => 'DBNAME',
];
I tested the environment detection like this:
[www-data#server]$ php artisan env
Current application environment: production
As you can see, it's working as intended. I then proceeded to run the migration like this:
php artisan migration:install
When I do, I get the following error:
[www-data#server]$ php artisan migrate:install --env=production
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
migrate:install [--database[="..."]]
Any idea why this might be? it looks like it's failing to load the .env.production.php file.
Does anyone know how to fix this error? Thanks in advance.
In the Laravel 4 docs it states that it needs to be .env.php on your production server.
Now, on your production server, create a .env.php file in your project
root that contains the corresponding values for your production
environment. Like the .env.local.php file, the production .env.php
file should never be included in source control.
So simply change your environment detection code to this
$env = $app->detectEnvironment(function() {
return file_exists(dirname(__FILE__) . '/../.env.php')
?
'production'
:
'local';
});
Note - you still use .env.local.php on your development server.