I've installed pgsql and set up my Laravel config/database.php as follows:
'connection_name' => [
'driver' => 'pgsql',
'host' => env('DB_HOST_2', '127.0.0.1'),
'port' => env('DB_PORT_2', '3306'),
'database' => env('DB_DATABASE_2'),
'username' => env('DB_USERNAME_2'),
'password' => env('DB_PASSWORD_2', ''),
'sslmode' => env('DB_SSLMODE_2'),
'charset' => 'utf8',
'prefix' => '',
'options' => [
'sslcert' => '/some/special/path.crt',
],
'schema' => 'public',
],
'connection_name' is located in the 'connections' section of database.php.
In artisan tinker I get the following error because it's still looking in the default location for the SSL certificate. I cannot get it to look in the right location for the cert.
>>> use Illuminate\Support\Facades\DB;
>>> DB::connection('connection_name')->getPdo()
Doctrine\DBAL\Driver\PDOException with message 'SQLSTATE[08006] [7] root certificate file "/home/wes/.postgresql/root.crt" does not exist
Either provide the file or change sslmode to disable server certificate verification.'
The root cert is set by "sslrootcert". This is the certificate that signed the server's cert.
"sslcert" sets the client cert. That is something different.
This is a pretty old question, but I ran into this issue today. My solution was a combination of jjanes answer and comment. I had to set the variable at a higher level and also change to "sslrootcert"
'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,
'search_path' => 'public',
'sslmode' => env('SSL_MODE'), <-- this says "verify-ca"
'sslrootcert' => env('PGSQL_SSL_CA') <-- this is fullpath
],
This worked when I used php artisan migrate on my PGSQL managed database on Digital Ocean.
Related
I deployed the project to azure and both the webpage displays properly and links work fine, but for the user registration I need to connect the database. Everything works well locally and I followed all the instructions of creating/connecting a sqsl db in azure but I get thte following 3 errors and not sure what to do, how to debug, its a project I was given to deply and didnt create myself,( I am only gona show the first 3 lines of the error since they are long):
UPDATE: It works if I disable the SSL on azure so its got something to do with my local app config for that
1-
SQLSTATE[HY000] [9002] SSL connection is required. Please specify SSL options and retry. (SQL: select count(*) as aggregate from `users` where `email` = ***#***.com)
in Connection.php line 647
at Connection->runQueryCallback('select count(*) as aggregate from `users` where `email` = ?', array('***#***.com'), object(Closure))
in Connection.php line 607
2-
(2/3) PDOException
SQLSTATE[HY000] [9002] SSL connection is required. Please specify SSL options and retry.
in PDOConnection.php line 50
at PDOConnection->__construct('mysql:host=***.mysql.database.azure.com;port=**+;dbname=uwiredb', '***#***', 'MySQLAzure2017', array(0, 2, 0, false, false))
in Connector.php line 65
at Connector->createPdoConnection('mysql:host=***.mysql.database.azure.com;port=***;dbname=***', '***#***', 'MySQLAzure2017', array(0, 2, 0, false, false))
in Connector.php line 44
3-
(1/3) PDOException
SQLSTATE[HY000] [9002] SSL connection is required. Please specify SSL options and retry.
here is the DB section of my .env file:
DB_CONNECTION=mysql
DB_HOST=mydbserver.mysql.database.azure.com
DB_DATABASE=mydb
DB_USERNAME=myuser
DB_PASSWORD=mypass
MYSQL_SSL=true
And here is the connection part of my database.php file in the config folder, I know the hosts
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'sslmode' => env('DB_SSLMODE', 'prefer'),
'options' => (env('MYSQL_SSL')) ? [
PDO::MYSQL_ATTR_SSL_KEY => '/ssl/BaltimoreCyberTrustRoot.crt.pem',
] : [],
],
'pgsql' => [
'driver' => 'pgsql',
'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' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'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' => '',
],
],
I know the host is set to local but that is how I understood it should be from the azure docs that say:
You can use the PHP getenv method to access the settings. the Laravel code uses an env wrapper over the PHP getenv. For example, the MySQL configuration in config/database.php looks like the following code:
PHP
Copy
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
...
],
Thanks
I have an application developed in laravel that communicate with 2 databases, once is mysql it's in linux shared hosting. The another is sql and is in a remote server.
In localhost it's work well, I use sqlsrv driver to communicate with sql database but when I pass the project to shared hosting it can't connect with database, just with mysql database.
What I have to ask the hosting provider specifically?
This is my connections parameters:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '8889'),
'database' => env('DB_DATABASE', 'dbname'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', 'pass'),
'prefix' => '',
],
'sql' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'remote_ip'),
'database' => env('DB_DATABASE', 'dbname'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', 'pass'),
'charset' => 'utf8',
'prefix' => '',
],
First you should have the php_sql_server driver installed on the server (as php_extension).
for more info read this: https://learn.microsoft.com/en-us/sql/connect/php/microsoft-php-driver-for-sql-server and (the download files) https://www.microsoft.com/en-us/download/details.aspx?id=20098
second, you should add the connection as a separate one in your env, like:
DB_HOST=127.0.0.1
DB_PORT=null
DB_DATABASE=GRH
DB_USERNAME=sa
DB_PASSWORD=sfsd42563
DB_HOST2=remote_ip
DB_DATABASE2=db_name
DB_USERNAME2=username
DB_PASSWORD2=password
adn on your config/database.php use as:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'sqlsrv' => [
'sqlsrv_Org' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST'),
'port' => null,//sqlsrv no port
'database' => env('DB_DATABASE2'),
'username' => env('DB_USERNAME2'),
'password' => env('DB_PASSWORD2'),
'charset' => 'utf8',
'prefix' => '',
],
I'm developing a project in laravel and I have to change the db connection.
I add a new connection and set this like default but when I run the app it uses the old connection and I don't understand why.
I'm not using .env just setting config/database.php.
'default' => env('DB_CONNECTION', 'DB2'),
'connections' => [
'DB2' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'IP'),
'database' => env('DB_DATABASE', 'DB2'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', '*****'),
'charset' => 'utf8',
'prefix' => '',
],
'DB1' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '2222'),
'database' => env('DB_DATABASE', 'DB1'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', '****'),
'charset' => 'utf8',
'prefix' => '',
],
],
How can I solve this?
Thank you
you just clear the config cache using the following commands:
php artisan config:clear
php artisan config:cache
I am configuring my postgresql driver in Laravel 5.4 for deployment to Heroku. Here is my config/database.php, the default is already set to pgsql
'pgsql' => [
'driver' => 'pgsql',
'host' => parse_url(getenv("DATABASE_URL"))['host'],
'database' => substr(parse_url(getenv("DATABASE_URL"))['path'], 1),
'username' => parse_url(getenv("DATABASE_URL")['username']),
'password' => parse_url(getenv("DATABASE_URL")['password']),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
When I commit I see this warning
PHP Warning: Illegal string offset 'username' in app/config/database.php on line 62
When run heroku run php artisan serveI am getting an error
[Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: PDO::__construct() expects parameter 2 to be string, array given
Here is my .env
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=forge
DB_USERNAME=postgres
DB_PASSWORD=
Your configuration array should look like the following if you want to get correct data from the .env provided.
'pgsql' => [
'driver' => 'pgsql',
'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' => '',
'schema' => 'public',
'sslmode' => 'prefer',
]
I found the answer in this site. It caters also mysql, and sqlite, please read
https://mattstauffer.co/blog/installing-a-laravel-app-on-heroku
After completed my project I deiced switch mysql to mongodb. I am using Laravel 5.4 version and for mongodb use jenssegers. For laravel mongdb installation I follow jenssegers installation documentations and installation successfully completed. But after installation I go for migration and use command php artisan migrate. When I use this command shown error InvalidArgumentException in /vendor/mongodb/mongodb/src/Database.php line 83: $databaseName is invalid:
My database.php
'default' => env('DB_CONNECTION', 'mongodb'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE', 'project_db'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'options' => [
'database' => 'admin' // sets the authentication database required by mongo 3
]
],
],
My .env
DB_CONNECTION=mongodb
DB_HOST=localhost
DB_PORT=27017
DB_DATABASE=admin
DB_USERNAME=
DB_PASSWORD=
And I also facing one more problem if whatever I change in .env and database.php like if I change port 27017 to 3303 but on browser shows 27017. I cleared cache and all. I don't know what is problem in my code.
These are the steps Envoyer (made by Laravel's creator) takes to deploy an app on production -- I've annotated them below:
# Clear the old boostrap/cache/compiled.php
php artisan clear-compiled
# Recreate boostrap/cache/compiled.php
php artisan optimize
# Migrate any database changes
php artisan migrate