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

fbr's avatar
Level 2

Forge Application Connecting to DB on another Forge Server

I have an application on Server1 that needs to use the database on Server2. Bother are forge managed servers. How can I connect to the mysql instance on Server2 from the Server1 application?

I understand that it is set up for ssh-only access. How can I disable that, or allow a specific IP to connect in a different way?

0 likes
5 replies
manojo123's avatar

The SSH connections usually works in port 22 so it wont affect database connections in port 3306.

You need to open port 3306(considering you are using defaults) and create a db remote user.

At your .env file set the right configurations

DB_CONNECTION=mysql
DB_HOST=EXTERNAL_IP_FROM_SERVER
DB_PORT=3306
DB_DATABASE=yourremotedb
DB_USERNAME=yourremoteuser
DB_PASSWORD=secret

And at your server, make sure that the port 3306 is opened in router and the db username is created with global access not only local.

You can create the global user with these commands

CREATE USER 'newuser'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'%';

You can also try to connect to your datase from command line to check connection before you try at your system

Consider 200.200.200.200 as your external IP

mysql -u your_username -p -h 200.200.200.200
2 likes
fbr's avatar
Level 2

Appreciate the reply, but I've jumped through al those hoops already. It's seemingly impossible to connect to a forge managed server in any way except through ssh.

So connecting mysql on port 3306 with username/password doesn't work. I don't know how to turn off this ssh-only connection mode.

richard@gorbutt.com's avatar

Can you open 3306 on the MySQL server using the Network option on the Forge menu for the server. You can open 3306 and limit it to the IP from the app server. Initially Forge locks it pretty well down.

2 likes
BLH's avatar

@FBR - @gorby is correct. You need to create a firewall rule in forge and open port 3306. You can find this in the networking section on the server details page.

Please or to participate in this conversation.