Reputation: 13
I have a website running on ubuntu server, and want to connect it to a database from another server. I used to do define('HOST','localhost');
when running with the database of my present server. but it's not 'localhost' anymore. should i remplace it with the other server IP ?
Thanks Y'all
Upvotes: 0
Views: 74
Reputation: 12462
Yes, you can put any IP address in your database connection string in place of 'localhost'. However, many hosting providers will prevent external connections (with good reason) from connecting to the MySQL server (port 3306). In fact, some MySQL/MariaDB installations by default don't listen on external network ports, so you may have to do some extra work to allow your servers to connect to each other.
Note that you have to have a database user that corresponds to that connection; for instance in MySQL/MariaDB the host value 'localhost' is specific to socket connections; switching to a TCP/IP networking connection means your existing user may not work (so you'll have to create another user with the correct host).
While it is very common to connect to other servers from within the same LAN segment, you should also take steps to prevent exposing this port to the internet in general and to prevent incoming connection attempts from reaching that machine.
Upvotes: 1