I have 2 servers both running Virtualmin and I’m trying to access a database on Server A from Server B. On Server A, I selected the appropriate server, then went to Edit Database > Remote Access and added the IP address of Server B.
Then I created a simple php script on Server B to try and connect to the database. I used the IP address as host. But I’m getting this error in apache’s access logs: AH01071: Got error 'PHP message: PHP Fatal error: Uncaught mysqli_sql_exception: No route to host in /home/domain/public_html/lab.php:8
Is there anything else that needs to be done? I can’t find a good tutorial on how to make this work.
and also make sure you have the mariadb port (3306 by default) open in your firewalld configuration and if you have a provider firewall open the port there also
Isn’t it weird that the logs are showing server 2’s IP. Shouldn’t it be server 1’s IP there?
I turned off Server 1 and then I get “Connection refused” error so the requests are being sent to Server 1. They are probably not getting interpreted the right way.
Got this response, I’m not sure if this the appropriate response.
Trying SERVER.1.IP...
Connected to SERVER.1.IP.
Escape character is '^]'.
5.5.5-10.6.18-MariaDB-ubu2004-log▒▒VS!EzZ0"▒▒-WoKgGkc2kFZqmysql_native_passwordConnection closed by foreign host.
Yes it is what you would expect, and just making sure server 1 is the database server, the connection error, I ran your code but rather than IP I used the hostname (I could not remember the IP address) and it worked fine. You have set the user essl to be able to connect from different IP addresses ? on server 1 go to webmin → servers → maria database server → User Permissions click the essl user and change the settings there or you can make a new user with the same name if you wish and make the settings something like this
Ignore the warning at the top, make sure any is active (Virtualmin created users will have this set to localhost ). As this is a remote user you may wish to set permissions to exactly what you want the remote user able to do. Last thing worth considering is enabling fail2ban’s mysql jail on server 1 with some fairly strict rules just to keep the hackers out of the database
Yes Server 1 or Server A has the database I want to connect to. Server 2 or Server B is what I’m connecting from. I have tried “Any” host but get the same error.
I want to post again what I’m doing.
I have 2 servers both running Virtualmin and I’m trying to access a database on Server A from Server B.
On Server A, I selected the appropriate server say callingmaria.com
Then went to Edit Database > Remote Access and added the IP address of Server B.
Next I created a new user from Edit Users. I don’t have Pro version so can’t create database user. I pressed “Add User” and here are the settings I chose
Now in Webmin > Servers > MariaDB Servers > User Permissions I have 2 new users for a total of 4:
i. essl@callingmaria.com, Host: Server B’s IP
ii. essl@callingmaria.com, Host: localhost
iii. callingmaria, Host: localhost
iv. callingmaria, Host: Server B’s IP
On Server B, I created a simple php script to try and connect to the database. I used the IP address as host. Here’s the code:
go to webmin → servers → maria database server → User Permissions click the essl@callingmaria.com user and change the permissions from there
you need to set
select table data
insert table data
update table data
delete table data
create tables
drop tables
manage indexes
alter tables
create temp tables
rather than the default
afterwards you should see something like