Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

longestdrive's avatar

Unable to connect to Laravel Forge Database on a new machine

Hi I have a laptop (running Ubuntu 22) that's set up to connect to Forge (via SSH) and it works perfectly to connect. I use PHPStorm and DataGrip to connect to the database. I now have a new PC running Ubuntu 24 that I'm trying to set up DataGrip and PHPStorm to connect to the database and having connection problems that I can't seem to resolve :(

Steps taken:

  1. I've created a new key pair and added the public key to Forge
  2. Created a new SSH connection in DataGrip using the key pair and clicked "test connection" and it says connection is successful
  3. I can see from the logs on Forge the connection was made
  4. I can log into the server via SSH using a terminal and get a successful connection
  5. I then add the database details to connect via SSH Tunnel - under the 'general' tab in Datagrip I have the following entries: -- Host: 127.0.0.1 -- Port: 3306 -- Authentication: User & Password -- User: forge -- Password: (the users database password as emailed to me when the server was provisioned)

When I then click on test connection I get an error: "SSH tunnel creation failed: connection reset"

On the forge SSH logs I then get:

Dec 30 08:03:01 twilight-sound CRON[1181962]: pam_unix(cron:session): session opened for user forge by (uid=0)
Dec 30 08:03:01 twilight-sound CRON[1181961]: pam_unix(cron:session): session opened for user forge by (uid=0)
Dec 30 08:03:02 twilight-sound CRON[1181962]: pam_unix(cron:session): session closed for user forge
Dec 30 08:03:02 twilight-sound CRON[1181961]: pam_unix(cron:session): session closed for user forge
Dec 30 08:03:10 twilight-sound sshd[1181971]: Accepted publickey for forge from X.XX.XX.XXX port 2026 ssh2: ED25519 SHA256:e***********************************
Dec 30 08:03:10 twilight-sound sshd[1181971]: pam_unix(sshd:session): session opened for user forge by (uid=0)
Dec 30 08:03:10 twilight-sound systemd-logind[746]: New session 783900 of user forge.
Dec 30 08:03:11 twilight-sound sshd[1182052]: error: connect_to 127.0.0.1 port 3306: failed.
Dec 30 08:03:11 twilight-sound sshd[1182052]: Received disconnect from X.XX.XX.XXX port 2026:11: 
Dec 30 08:03:11 twilight-sound sshd[1182052]: Disconnected from user forge X.XX.XX.XXX port 2026
Dec 30 08:03:11 twilight-sound sshd[1181971]: pam_unix(sshd:session): session closed for user forge
Dec 30 08:03:11 twilight-sound systemd-logind[746]: Session 783900 logged out. Waiting for processes to exit.
Dec 30 08:03:11 twilight-sound systemd-logind[746]: Removed session 783900.
Dec 30 08:03:21 twilight-sound sshd[1182054]: Accepted publickey for root from XXX.XXX.XXX.XXX port 41694 ssh2: RSA SHA256:***************************************************
Dec 30 08:03:21 twilight-sound sshd[1182054]: pam_unix(sshd:session): session opened for user root by (uid=0)
Dec 30 08:03:21 twilight-sound systemd-logind[746]: New session 783901 of user root.
Dec 30 08:03:21 twilight-sound systemd: pam_unix(systemd-user:session): session opened for user root by (uid=0)

I can see the error connecting to the database but don't understand how to fix or why - given all the information is the same on the other machine. I've tried creating new database users and using them instead - same result I've also installed mysql workbench and tableplus but both fail at the same point I've also tried connecting in tableplus via the provided URL (from Forge) but that also fails

Is there something missing on Ubuntu 24 I need to install to get this to work as expected?

Can't work this out :(

Thank you

0 likes
2 replies
LaryAI's avatar
Level 58

It sounds like you're experiencing an issue with the SSH tunnel setup for your database connection on your new Ubuntu 24 machine. Here are some steps and checks you can perform to troubleshoot and resolve the issue:

  1. Verify SSH Tunnel Configuration:

    • Ensure that the SSH tunnel is correctly configured in DataGrip. The SSH host should be your server's IP address, and the SSH port should be the one used by your server (usually 22 unless changed).
    • Make sure the local port (3306) is not being used by another service on your local machine. You can check this by running sudo lsof -i :3306 in your terminal.
  2. Check MySQL Service:

    • Ensure that the MySQL service is running on your server. You can do this by SSHing into your server and running:
      sudo systemctl status mysql
      
    • If it's not running, start it with:
      sudo systemctl start mysql
      
  3. Firewall and Security Groups:

    • Check if there are any firewall rules or security groups that might be blocking the connection. Ensure that your server allows connections on the necessary ports.
  4. SSH Key Permissions:

    • Ensure that your SSH key permissions are correct. The private key should have 600 permissions:
      chmod 600 /path/to/your/private/key
      
  5. SSH Config File:

    • If you have an SSH config file (~/.ssh/config), ensure there are no conflicting settings that might affect the connection.
  6. Test SSH Tunnel Manually:

    • You can manually test the SSH tunnel by running the following command in your terminal:
      ssh -L 3306:127.0.0.1:3306 forge@your-server-ip
      
    • Keep this terminal open and try connecting to the database again using DataGrip.
  7. Check Logs for More Details:

    • Review the MySQL logs on your server for any additional error messages that might provide more insight. The logs are typically located at /var/log/mysql/error.log.
  8. Update Software:

    • Ensure that your DataGrip and PHPStorm are up to date. Sometimes, updates can resolve compatibility issues.
  9. Try Different SSH Client:

    • If the problem persists, try using a different SSH client to see if the issue is specific to DataGrip.

By following these steps, you should be able to identify and resolve the issue with your SSH tunnel and database connection. If the problem persists, consider reaching out to the support forums for DataGrip or Laravel Forge for more specific assistance.

longestdrive's avatar

Following step 6 I get the following response:

***@***-******:~$ ssh -L 3306:127.0.0.1:3306 [email protected]
bind [127.0.0.1]:3306: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 3306
Could not request local forwarding.
Welcome to Ubuntu 20.04.5 LTS (GNU/Linux 5.4.0-176-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Mon Dec 30 08:32:06 UTC 2024

  System load:           0.14
  Usage of /:            41.9% of 24.05GB
  Memory usage:          44%
  Swap usage:            92%
  Processes:             152
  Users logged in:       0
  IPv4 address for eth0: XXX.XX.XXX.XXX
  IPv4 address for eth0: 10.16.0.5
  IPv6 address for eth0: 2a03:b0c0:1:d0::e9a:6001
  IPv4 address for eth1: 10.106.0.2

Now in an area I'm not confident in :( BTW I also have Docker installed (as I do on the laptop) on which I do my development but not sure now if that's interfering

Please or to participate in this conversation.