When we start creating a database driven website using PHP, the first thing we do is testing our application using the local host package like: WAMP for windows, MAMP for mac, or XXAMP for both. In the early stages of development workflow we might need to create a local database with simple tables using PHPMyAdmin locally, but when the application is growing larger and when the time is came to start developing and testing the project using our servers, we have to connect to a remote MySQL database. Due to many hosting providers, there are different ways to configure that type of connection, or finding the right IP address for our own servers.
Through my search earlier in the last semester, I found the table that contains a list for most of the hosting companies from codex.wordpress.org and it could be useful for many PHP developers, below is just a sample for GoDaddy and you can visit the actual page in codex.wordpress.org that contains the entire hosting.
GoDaddy – cPanel Hosting: localhost
GoDaddy – Plesk Hosting: Use the IP address shown in the Databases Section in Plesk. Do not include: 3306
If your hosting company using cPanel which is built on Linux platform, in this case, we need to enable remote MySQL from cpanel in order to connect our PHP files that are running on our PCs using local Apache server with the MySQL database on the server. By enabling remote database, I mean adding the IP address for your computer to the web server host list in cpanel.
In windows, there are different ways to know your IP address by following either one of the following steps:
First Way: using CMD
- Go to run command and type: CMD to open command prompt window
- Type: ipconfig and this will list the info of your network connection.
The value that we are concerning about is IPv4 Address: XXX.XXX.X.XX.
- Go to Control Panel then type Adapter in the search box.
From the search result, double click the View Network connections to open your network if it’s Ethernet or Wi-Fi,
- Double click the one that in use (the activated one)
From the Wi-Fi / Ethernet Status window, click on details and you will see the value of IPv4 Address for your current PC.
By the way, if nee to know IP address for your URL, you can also open the CMD window and type: ping www.YourDomainName.com. Or when you login into your cpanel you will see in the left pane Shared IP Address which is the same.
Finally, you need to log into your cpanel (www.YourDomainName.com/cpanel) to add your PC IP address as a remote web server to communicate with the database in your hosting company. And to do that, you can double click the remote MySQL server, then type your IP address in the box and click Add Host button as shown below: