Laravel: Database SSL connection not working - mysql

I tested the ssl connection with my (Open SSL) generated certificates via the MySQL workbench app and it was working perfectly fine via ssl. However, when I try to use a ssl connection to my remote database with Laravel I get errors. On my local machine I get a 502 Bad Gateway error when visiting my laravel website and on my online test setup I get a SQLSTATE[HY000] [2002] error.
Config:
'mysql' => [
'driver' => 'mysql',
'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' => '',
'strict' => true,
'engine' => null,
'modes' => [
//'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
],
'options' => [
PDO::MYSQL_ATTR_SSL_KEY => base_path('ssl/client-key.pem'),
PDO::MYSQL_ATTR_SSL_CERT => base_path('ssl/client-cert.pem'),
PDO::MYSQL_ATTR_SSL_CA => base_path('ssl/ca-cert.pem')
]
],
This is an error that is logged in my online setup in the laravel log file:
[previous exception] [object] (PDOException(code: 0): PDO::__construct(): Unable to locate peer certificate CN at /var/www/vhosts/website.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:38)
[stacktrace]
I'd really appreciate any hints.

PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,

Related

TYPO3: Access denied to database after moving installation

I have migrated successfully my TYPO3 v10 site under mampp. Now I get this exception:
Doctrine\DBAL\Exception\ConnectionException An exception occurred in driver: Access denied for user 'dbxx'#'localhost'
My configuration entry is the following:
'DB' => [
'Connections' => [
'Default' => [
'charset' => 'utf8mb4',
'dbname' => 'mysite_f10',
'driver' => 'mysqli',
'host' => 'localhost',
'password' => 'root',
'tableoptions' => [
'charset' => 'utf8mb4',
'collate' => 'utf8mb4_unicode_ci',
],
'user' => 'root',
],
],
],
Is it possible, that TYPO3 stores still my old database values in a cache? And if, how can I clear my cache manually?
Database credentials are not cached anywhere. I assume that you changed the values in LocalConfiguration.php. You should check your installation if there is a file called AdditionalConfiguration.php in the same directory as LocalConfiguration.php. All values in that file overwrite values from LocalConfiguration.php.

Trying to connect laravel to mysql but i keep getting an error

I have my laravel app running and i'm trying to connect it to a Mysql database. I'm using XAAMP for this. After getting Apache and Mysql is running (Mysql is running on port 3308). I reconfigured my .env file and database.php file and I've run php artisan config cache. However when i try to create a database from my terminal using create database xxx, xxx database is created but when i check phpmyadmin on my browser, i can't find the xxx datatbase.
Here's my database.php file:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3308'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'test123'),
'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'),
]) : [],
],
And here's my .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3308
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=test123
Solved it but i had to clear up port 3306 so that XAAMP mysql could use it. Cleared it by ending all mysql tasks under task manager.

Laravel DB Connection to a separate connection works locally but doesn't inside server

I am trying to connect a second database in a separate server to my Laravel app and currently I can't get a connection to it. I am able to connect to the database normally through my local environment when I type DB::connection('connection')->table('users')->get() inside of php artisan tinker.
But when I try the same when I ssh into my server to test the connection I get a connection timeout.
SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from
users)'
Here are my connection settings:
'connection' => [
'driver' => 'mysql',
'host' => env('DB_HOST_TWO', '127.0.0.1'),
'port' => env('DB_PORT_TWO', '3306'),
'database' => env('DB_DATABASE_TWO', ''),
'username' => env('DB_USERNAME_TWO', ''),
'password' => env('DB_PASSWORD_TWO', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
I verified with my environmental variables, both local and in the server they have the same credentials

Master Slave Configuration in Laravel 5.5

How to configure Laravel 5.5 with master slave MySQL replication ?
I want to make write operations and read operations in master and slave respectively .
Optional: Is there any way to do connection pooling and max / min no of open connections in ideal conditions. ?
Just change your config/database.php file to include read (slave) and write (master) hosts like so like the Laravel docs suggest:
'mysql' => [
'read' => [
'host' => '192.168.1.1',
],
'write' => [
'host' => '196.168.1.2'
],
'sticky' => true,
'driver' => 'mysql',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
],

Multiple database connection failed, PDOException in Connector.php line 47 SQLSTATE[HY000] [2002] A connection attempt failed

I am trying to connect remote database from my localhost, the cause of I want to store data localhost to remote server. Now I want to show simply users table info it get form my localhost and different variable show remote server users table info . I write the code example here :
In my Config/database.php:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'realstate'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'shahin' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '104.219.248.3'),
'database' => env('DB_DATABASE', 'laraveldb'),
'username' => env('DB_USERNAME', 'laraveldb_username'),
'password' => env('DB_PASSWORD', 'secret'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
In Route.php :
Route::get('mpdb',function(){
$userArray = DB::table('users')->get();
echo "<pre>";
print_r($userArray);
echo "</pre><br>";
$users2 = DB::connection('shahin');
$u = $users2->table('users')->get();
echo "<pre>";
print_r($u);
});
Local Database work's properly but Remote database get error!!
ERROR : SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
To allow external web servers to access your MySQL databases, add their domain names to the list of hosts that are able to access databases on your web site.
see a hosted cpanel demo(Image)
If you want to all incoming hosts you may access like this %.%.%.%
You can see this picture
How to permit other incoming host(Image)