2

I want to connect to a remote database from my localhost, but the remote DB only allows connections from whitelisted IPs.

Since I'm on a dynamic IP from my ISP, I can't have my home IP whitelisted, because it will just change again.

I have a VPS with full root access and a fixed IP, which is whitelisted.

What I want is to:

  • Run a php script from my local machine
  • Connect to the remote database via my VPS
  • Get the query results back to my local machine for handling

How do I do this?

2 Answers 2

1

Having a PHP proxy to execute arbitrary SQL statements from any IP address is really dangerous. I would suggest you abstract the SQL statements into an API, so rather than allowing any query through, you limit it to a specific set of queries to retrieve or update specific data. Your local machine could then just call that API to retrieve or update information.

Sign up to request clarification or add additional context in comments.

1 Comment

I know, I would never do it myself, but my client was using a cloud solution that did exactly this.
0

The key problem you need to solve is finding a host with a static IP address you can add to the whitelist. You say that you have already solved that problem. However you have not mentioned what OS is running on the vps nor the client. If both are Linux, then you can do this with just iptables. If either or both are mswindows then you could use socat, but if it were me, I'd go with a stunnel link between the client and proxy (although if the whitelist on the server is only applied to the mysql connection, you could terminate the stunnel connection on the server and skip the proxy altogether) using client certificate authentication or an SSH tunnel.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.