cPanel & WHMMySQL/MariaDB

Configure Remote MySQL Database in cPanel

You may have created a Remote MySQL Database Server and now you want to use that in cPanel. it’s possible to host your website on one server and your MYSQL database on another. This is called a Remote MYSQL Database cPanel. Whilst most users will never need to use this feature it is handy to mitigate certain risks. Users who are Resellers or Web Hosting customers will need to contact the support team to allow Remote MYSQL Connections.

It’s worth pointing out if you are setting up a remote MYSQL Database the remote database server should be fast. We recommend an NVMe VPS. These are faster than an SSD server. It should also not be too far away from your production server. Try to get a server in the same DC or at least the same country.

Setup Remote MySQL Database

To set up a Remote MYSQL Database on your website server, access WHM and in the search bar type “SQL”. Click the “Additional MySQL Access Hosts link. In the Additional MySQL Access Hosts box place the IP of the remote MYSQL server.

If this is a cPanel server then your MySQL database server shares the same IP as your server. Click save once done.

Configure cPanel Firewall

Next, in your firewall configuration, you need to open port 3306 to allow your server to communicate with the remote MySQL server. If you are using CSF you can click “Firewall Configuration” and add the port to the IPv4 port settings.

Now on your Remote MySQL server repeat the above steps but place your website server IP in the Additional MySQL Access Hosts host. So, in your production server, you will have your MySQL server IP and in your MySQL server, you will have your website server IP. If you are using any dedicated IPs you should also place them in these boxes. Click Save. On your MySQL server ensure port 3306 is open.

Finally, in cPanel on your Remote MySQL server login and click the Remote MySQL icon and place your website in http://www.domain.com format. This will allow connections from your website to your MySQL Database.

Repeat the above step on your website server but this time ensure your MySQL IP is listed and any website you are using.

Add Database To Software Install

You can now place your remote database username and password in any configuration files you have. Remember to remove any reference to “localhost” which is the local MySQL server and place your remote MySQL server IP in this field. For example, if our remote MySQL serves IP was 192.168.0.100 your High Availability WordPress Website configuration file would look like this;

define( 'DB_NAME', 'database_name_here' );
define( 'DB_USER', 'username_here' );
define( 'DB_PASSWORD', 'password_here' );
define( 'DB_HOST', '192.168.0.100' );

When you visit your website via http you should not see your website running off your website server but the database is being loaded from the remote server. If you see any “Error Connecting To Database” issues you need to double-check your setup. Ensure your firewall is not blocking the connection.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button