Configure a Remote MySQL Database in cPanel
In cPanel it’s possible to host your website on one server and your MYSQL database on another server, this is called a Remote MYSQL Database. 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. Remote MYSQL is considered a security risk and is disabled by default on all cPanel servers.
It’s worth pointing out if you are setting up a remote MYSQL Database the remote database server should be responsive to cut down the time it takes to load the database on your website. This means ideally it should be running SSD storage and not be too far away from your production server.
To setup Remote MYSQL Databases on your website server, access WHM and in the search bar type “SQL” and 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.
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 websites servers IP in the Additional MySQL Access Hosts host. So, in your production server you will have your MySQL servers IP and in your MySQL server, you will have your website servers 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.
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 servers IP in this field. For example, if our remote MySQL serves IP was 192.168.0.100 your WordPress configuration file would look like this;
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define( 'DB_NAME', 'database_name_here' ); /** MySQL database username */ define( 'DB_USER', 'username_here' ); /** MySQL database password */ define( 'DB_PASSWORD', 'password_here' ); /** MySQL hostname */ 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.
How was this article? – Configure a Remote MySQL Database in cPanel
More from Editor Picks
Stop Spam Being Received On cPanel Servers (Filter out Spam)This guide is about stopping spam being received on a cPanel …
Optimize a SolusVM VPS Server Running Virtuozzo/ OpenVZFor the most part, the default CPU setting used by SolusVM will be …