laraveldirectadmin

Remote access to a DirectAdmin database from my Laravel app


I am building a central website (Laravel) which will connect different Laravel applications hosted in different DirectAdmin hosting.

I am getting this error-- SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. (SQL: SELECT * FROM users LIMIT 10)

How can i connect remote database hosted in DirectAdmin??

This is what I am using to connect another database:

'mysql2' => [
    'driver' => 'mysql',
    'host' => '**.***.***.**',
    'port' => '3306',
    'database' => 'db_name',
    'username' => 'db_user',
    'password' => 'dppass',
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'prefix_indexes' => true,
    'strict' => false,
    'engine' => null,
],

And from controller:

public function adminHome(){
    $news = \DB::connection('mysql2')->select("SELECT * FROM users LIMIT 10");
    dd($news);
 }

Solution

  • I solved this problem. Just need to add host name to Remote host. From User panel go MySQL Menu > choose a Database > and add your host. enter image description here