0

Hey I'm a bit new to this kind of thing, I hope the title makes sense.

Basically I have a mysql server running on a LAMP stack, with some mean legacy code, by which all connections to the database are using mysql_connect("localhost", "user", "pass"). (I know it's bad, I didn't write it!).

I would like to run my own local version of our website for debugging/dev purposes, but I can't figure out how to connect to our database (we have a test-database running remotely that is updated every day with the live data). I have tried remotely connecting but I can't figure it out.

I was wondering if I keep the code (with "localhost" connection written in), and use some kind of SSH tunneling to "trick" the code into connecting to the remote database? Or would it perhaps be easier to set up some kind of mysql 'server' on my local machine? Using phpstorm's in built "database" functionality, I managed to connect to our database using ssh tunneling, but from there I'm completely lost. Again I'm new to this, so I apologise if this sounds very naive.

Any kind of help for a solution would be great.

13
  • You should be able to connect to the remote database, most likely the remote server that has the test database need to be configured to allow the connection from your local environment. Commented Jul 15, 2016 at 9:48
  • I did set up my user to have full "grants" 'k4kuz0'@'%', which I believe means that I can connect from "anywhere". But I'm not even sure if it can accept remote connections generally? In the services list, mysqlis running but mysqldis not? Which I had taken to be the "remote" connection part? Commented Jul 15, 2016 at 9:49
  • It's not only the database user but the server properly has a firewall as well, you need to make sure you can connect to it. Commented Jul 15, 2016 at 9:50
  • hmm i dont know if i understood you correct. is your web server and mysql server in same server? if no you shoud set mysql bind address. read link below: help.ubuntu.com/community/ApacheMySQLPHP Commented Jul 15, 2016 at 9:52
  • I still have bind-address = 127.0.0.1 sitting in my /etc/mysql/my.cnf, does that need to be commented out...? Commented Jul 15, 2016 at 9:53

1 Answer 1

0

If you are on Linux you must install Stunnel on both Client and Server.

Take a look here: https://blog.thesysadmins.co.uk/using-stunnel-to-encrypt-unsecure-connections.html

By configuring properly Stunnel you will be able to use mysqli_connect with "locahost" while actually referring to a remote server.

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

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.