I am currently doing a local project, using MAMP with PHP version 7.4.21 and I can't seem to run my system because the database is not configured correctly.
Here's my .env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost:8888/VMLM
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=vmlm
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
and here's my database.php
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',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'vivemlm'),
'username' => env('DB_USERNAME', 'admin'),
'password' => env('DB_PASSWORD', 'admin'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=vivemlm
DB_USERNAME=admin
DB_PASSWORD=admin
DB_CONNECTION is the driver that you will use
Related
I want to create a second database to act as a backup. I've been following another SO question solution and other websites which leads to the same thing. I've added a new DB connection in .env and configured it in database.php, cleared out the cache using php artisan config:cache. When I try to migrate using php artisan migrate --database=backup_literature_review_management, it says InvalidArgumentException, Database connection [backup_literature_review_management] not configured.
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=literature_review_management
DB_USERNAME=root
DB_PASSWORD=
DB_CONNECTION_BACKUP=mysql
DB_HOST_BACKUP=127.0.0.1
DB_PORT_BACKUP=3306
DB_DATABASE_BACKUP=backup_literature_review_management
DB_USERNAME=root
DB_PASSWORD=
database.php
'connections' => [
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'mysql2' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST_BACKUP', '127.0.0.1'),
'port' => env('DB_PORT_BACKUP', '3306'),
'database' => env('DB_DATABASE_BACKUP', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
],
Cleared cache before migrating
php artisan config:cache
Trying to migrate to 2nd DB
php artisan migrate --database="backup_literature_review_management"
Error
InvalidArgumentException, Database connection [backup_literature_review_management] not configured.
You are calling the wrong connection. Use this:
php artisan migrate --database="mysql2"
You can also define the connection inside the migration file like:
Schema::connection('mysql2')->create('table', function (Blueprint $table) {...
With this last command, you can ommit --database="mysql2 in the migration command. I personally prefer to declare the connection inside the migration file.
Hope it helped!
I'm trying to publish my Laravel 5.8 app on production hosting. I've uploaded the files and have made the changes in .env file. But still while accessing my application., it throws error:
Access denied for user 'root'#'127.0.0.1' (using password: NO)
Below is my .env file:
DB_CONNECTION=mysql
DB_HOST= ip
DB_PORT=3306
DB_DATABASE=secret
DB_USERNAME='secret'
DB_PASSWORD='secret'
I have also made changes in database.php:
'users' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'secret'),
'port' => env('DB_PORT', '3306'),
'database' => env(‘DB_DATABASE', 'secret'),
'username' => env('DB_USERNAME', 'secret'),
'password' => env('DB_PASSNORD', 'secret'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO: :I'IYSQL_ATTR_SSL_CA => env( 'MYSQL_ATTR_SS L_CA' ),
]) : [],
},
Try.
php artisan config:cache
then
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=secret //enter your right databse name
DB_USERNAME=secret //please check your username
DB_PASSWORD=secret //please check your password
or
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=secret //enter your right databse name
DB_USERNAME=root //please check your username
DB_PASSWORD=enter your correct password //please check your password
change your databse.php
'users' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env(‘DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSNORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO: :I'IYSQL_ATTR_SSL_CA => env( 'MYSQL_ATTR_SS L_CA' ),
]) : [],
},
As a comment suggest, use localhost instead of 127.0.0.1, but also, same error occurs to me and the problem was the Laravel project cache: just use php artisan config:cache to re-cache the files, or just delete all the files inside the bootstrap/cache folder
I'm trying to make an API using Laravel, but I've run in to a problem.
I've started a second version of the project, but even though I've changed the database to a second version database, it's still trying to take from the first versions database.
Version 1 database is APITest, version 2 database is APITest2
Image of 'apitest' search of entire folder
The only occurrences of 'APITest' is in the logs from when I was setting up the database, I'm using Laravel, Gitbash and Xampp, I've tried clearing the cache and restarting the server. I can't figure out where it's still even connected to the old database.
The cache clear(s) I did:
php artisan config:cache
php artisan config:clear
Thanks for any help you can give, let me know if there's any other pics/snippets I can provide
Edit: Image of the error
Database Config file
<?php
use Illuminate\Support\Str;
return [
'default' => env('DB_CONNECTION', 'mysql'),
'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',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'APITest2'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
],
'migrations' => 'migrations',
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'APITest2'), '_').'_database_'),
],
'default' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
],
'cache' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
],
],
];
.env file
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:GMwBL1+vtz/mfl5tMrUmwHnTvAvjA5iRMqwpiQKXOfs=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=APITest2
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
The project's path in the search image doesn't match the path in the error image, the web-server is probably still pointing to your old project. Change the root folder and restart the server.
I'm already done with my project in Laravel but when I try to host it on 000webhost it shows me
coindeorotest.000webhostapp.com is currently unable to handle this
request. HTTP ERROR 500
I already followed the instructions here https://www.000webhost.com/forum/t/code-error-500-on-laravel-projects/127667/11 but it keeps me getting an error. I already migrated the databases in my project. Can someone help?
database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'id10201702_adminpanel'),
'username' => env('DB_USERNAME', 'id10201702_root'),
'password' => env('DB_PASSWORD', '12345'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'mysql2' => [
'driver' => 'mysql',
'host' => env('DB_HOST_SECOND', 'localhost'),
'port' => env('DB_PORT_SECOND', '3306'),
'database' => env('id10201702_ricjac8_orocoin'),
'username' => env('DB_USERNAME', 'id10201702_root2'),
'password' => env('DB_PASSWORD','12345'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
.env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:HoQcNyCc5KEGw4yjqpBIdKzTC+yeDoOJcerVMEVx+fs=
APP_DEBUG=true
APP_URL=http://localhost
DEBUGBAR_ENABLED=true
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=id10201702_adminpanel
DB_USERNAME=id10201702_root
DB_PASSWORD=12345
DB_CONNECTION_SECOND=mysql2
DB_HOST_SECOND=localhost
DB_PORT_SECOND=3306
DB_DATABASE_SECOND=id10201702_ricjac8_orocoin
DB_USERNAME_SECOND=id10201702_root2
DB_PASSWORD_SECOND=12345
I want to set multiple connections in Laravel application.
I tried using database.php is:
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'reports_db'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'pass'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'mysql1' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'a2z'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'root'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
],
and .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=reports_db
DB_USERNAME=root
DB_PASSWORD=pass
CL_DB_CONNECTION=mysql1
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=a2z
DB_USERNAME=root
DB_PASSWORD=root
Inside controller
public function index()
{
$ad= new Ad;
$ad->setConnection('mysql1');
$ad = ad::get();
echo $job;
}
But I am not able to set up mysql1 connection.Can you please tell me how to achieve this?
you are actually using the same connection parameters both the time as you are using the same env values in your database.php:
Your .env file should contain something like this:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=reports_db
DB_USERNAME=root
DB_PASSWORD=pass
TWO_DB_CONNECTION=mysql1
TWO_DB_HOST=127.0.0.1
TWO_DB_PORT=3306
TWO_DB_DATABASE=a2z
TWO_DB_USERNAME=root
TWO_DB_PASSWORD=root
and database.php should be something like this:
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'reports_db'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'pass'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'mysql1' => [
'driver' => 'mysql',
'host' => env('TWO_DB_HOST', 'localhost'),
'port' => env('TWO_DB_PORT', '3306'),
'database' => env('TWO_DB_DATABASE', 'a2z'),
'username' => env('TWO_DB_USERNAME', 'root'),
'password' => env('TWO_DB_PASSWORD', 'root'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
],