PhpStorm 2025.1 Help

Connect to a database with SSH

This topic gives you examples of how you can connect to databases running in isolated networks through an SSH tunnel and a jump host.

For more information about how to use SSH in PhpStorm, refer to the SSH and SSL topic.

Cloud database

Let us consider the following example. MySQL database is running remotely in a cloud, the connection has to be established through a jump host. You need to authenticate using your encrypted private key file. To create a data source and run a test connection to your database, do the following:

  1. In the Database tool window, click the New icon New on the toolbar and navigate to Data Source | MySQL.

  2. Click the SSH/SSL tab and select the Use SSH tunnel checkbox.

  3. Click the Add SSH configuration Add SSH configuration.

  4. In the SSH Configurations dialog, add a new configuration by doing the following:

    1. Click the Add button.

    2. In the Host and Port fields, specify the connection details of your jump host. For example, my-jump-host.amazonaws.com, 22.

    3. Enter your username in the Username field.

    4. In this tutorial, we use encrypted private key file and public key file to authenticate. From the Authentication type list, select Key pair.

    5. To provide your private key file, click the Browse icon Browse in the Private key file field and select the file.

    6. Specify your passphrase in the Passphrase field.

    7. Click Test Connection to run a test connection to the jump host.

      SSH configuration and successful test connection to the jump host
    8. In the SSH Configurations dialog, click OK to confirm the new SSH configuration settings.

  5. On the General tab of the Data Sources and Drivers dialog, specify your database connection details:

    1. In the Host and Port fields, specify your database server address and port number. For example, mysql-ssh.my-account.my-region.amazonaws.com and 3306.

    2. From the Authentication dropdown, select User & Password.

    3. In the User and Password fields, type your user credentials.

    4. In the Database field, type the database name to which you want to connect. In our example, testdb.

    5. In the URL field, PhpStorm generates the JDBC URL automatically using the values of other connection settings.

      If you need to use a JDBC URL with certain additional settings, paste it in the URL field.

      For example, jdbc:mysql://my-endpoint.amazonaws.com:3306/testdb.

  6. Click the Test Connection link at the bottom of the connection details area to initiate a test connection to your database.

    Test Connection link
  7. Click OK to create the data source.

Connection settings of the MySQL [Cloud, SSH] data source

Database in a Docker container

In this example, PostgreSQL database is running in a Docker container, and it is not directly accessible. The connection has to be established through a jump host running in another Docker container. You need to authenticate using your encrypted private key file. To create a data source and run a test connection to your database, do the following:

  1. In the Database tool window, click the New icon New on the toolbar and navigate to Data Source | PostgreSQL.

  2. Click the SSH/SSL tab and select the Use SSH tunnel checkbox.

  3. Click the Add SSH configuration Add SSH configuration.

  4. In the SSH Configurations dialog, add a new configuration by doing the following:

    1. Click the Add button.

    2. In the Host and Port fields, specify the connection details of your jump host running in Docker container. For example, localhost and 2222.

    3. Enter your username in the Username field.

    4. In this tutorial, we use encrypted private key file and public key file to authenticate. From the Authentication type list, select Key pair.

    5. To provide your private key file, click the Browse icon Browse in the Private key file field and select the file.

    6. Specify your passphrase in the Passphrase field.

    7. Click Test Connection to run a test connection to the jump host.

      SSH configuration and successful test connection to the jump host
    8. In the SSH Configurations dialog, click OK to confirm the new SSH configuration settings.

  5. On the General tab of the Data Sources and Drivers dialog, specify your database connection details:

    1. In the Host and Port fields, specify your database server address and port number. For example, 172.19.0.3 and 5432.

    2. From the Authentication dropdown, select User & Password.

    3. In the User and Password fields, type your user credentials.

    4. In the Database field, type the database name to which you want to connect. In our example, guest.

    5. In the URL field, PhpStorm generates the JDBC URL automatically using the values of other connection settings.

      If you need to use a JDBC URL with certain additional settings, paste it in the URL field.

      For example, jdbc:postgresql://172.19.0.3:5432/guest.

  6. Click the Test Connection link at the bottom of the connection details area to initiate a test connection to your database.

    Test Connection link
  7. Click OK to create the data source.

Connection settings of the MySQL [Cloud, SSH] data source
Last modified: 15 May 2025