How to set up and connect to a remote mysql database via SSH from Yii2 advanced?

Viewed 155

One of the databases in Yii2 advanced must be connected remotely. Server connects to remote server via SSH. Yii2 as installed on ubuntu server.

1 Answers

You can specify the database hostname (e.g. a hostname or an IP address as 127.0.0.1) and port as part of the dsn in /environments/dev/common/config/main-local.php:

'components' => [
    'db' => [
        'class' => '\yii\db\Connection',
        'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
        ...
    ],
],

Docs are here: Application components

Related