'LinKin Posted June 22, 2014 Share Posted June 22, 2014 Hello, I've a VPS, and I made a database with public access, all my scripts work fine (I'm using them in external servers / not the servers that are hosted in the VPS) and they work flawlessly, but now, I just found out that they don't work on the servers that are hosted in the same VPS. I'm using dbConnect and I provide the IP / pass / username , etc... How could I connect to the db when I'm running the script in a server on the same VPS? Maybe not using the IP but localhost? And by the way why is it like this? Shouldn't it work with the IP too? Thanks. Link to comment
Moderators Citizen Posted June 22, 2014 Moderators Share Posted June 22, 2014 Maybe not using the IP but localhost? Yes, why didn't you try ? And by the way why is it like this? Shouldn't it work with the IP too? All depends of the router configuration. Look at the following schema: VPS Server is hosting your database and VPS Server2 is hosting your mta servers. When your mta servers connect to your database using the public ip of VPS Server (123.123.123), Hoster Router2 knows the route to go to this ip. But if the mta servers are running on VPS Server and try to connect to itself (VPS Server) using its public ip (123.123.123), then if Hoster Router isn't configured to handle this case, he won't know who is 123.123.123.123. So to avoid going out of VPS Server and ask to Hoster Router, just use 127.0.0.1 or localhost as database ip. It will prevent useless bandwith usage between VPS Server and Host Router. Link to comment
'LinKin Posted June 22, 2014 Author Share Posted June 22, 2014 Oh no.. It still doesn't work. I tried these as the hosts: localhost, 127.0.0.1 Tried this as the usernames: root And these as the passwords: thePassOfVPS, thePassOfPhpMyAdmin Also tried with port=3306 I combined them, but none worked Link to comment
xXMADEXx Posted June 23, 2014 Share Posted June 23, 2014 Post the code that you use for dbConnect. Link to comment
'LinKin Posted June 23, 2014 Author Share Posted June 23, 2014 Here, all the combinations I tried: dbHandler = dbConnect("mysql", "dbname=randomName;host=localhost", "username", "password", "share=1") dbHandler = dbConnect("mysql", "dbname=randomName;host=127.0.0.1", "username", "password", "share=1") dbHandler = dbConnect("mysql", "dbname=randomName;host=localhost", "root", "vpsPassword", "share=1") dbHandler = dbConnect("mysql", "dbname=randomName;host=127.0.0.1", "root", "vpsPassword", "share=1") dbHandler = dbConnect("mysql", "dbname=randomName;host=localhost", "root", "mysqlPassword", "share=1") dbHandler = dbConnect("mysql", "dbname=randomName;host=127.0.0.1", "root", "mysqlPassword", "share=1") dbHandler = dbConnect("mysql", "dbname=randomName;host=localhost;port=3306", "username", "password", "share=1") dbHandler = dbConnect("mysql", "dbname=randomName;host=127.0.0.1;port=3306", "username", "password", "share=1") Everything returns "Could not connect to the database" Another relevant data is: to allow remote access I edited something at /etc/mysql/my.cnf I commented this line: bind-address = myVPS_IP So it's like this now: #bind-address = myVPS_IP Link to comment
Moderators Citizen Posted June 24, 2014 Moderators Share Posted June 24, 2014 Hmmm interesting. Did you restart the mysql server (or the whole vps) after commented this line ? If yes, then I would try to put bind-address = 127.0.0.1 to make it listening on the loopback ip. If it's still doesn't work, comment this line again and create a new user with correct permissions in phpMyAdmin and then try to connect again (with 127.0.0.1, or your vps ip). We have to figure this out ! That's so weird ! Link to comment
'LinKin Posted June 24, 2014 Author Share Posted June 24, 2014 This is so wierd! I totally agree with that.. Yesterday it wasn't connecting, but now it does.. and I've made no changes at all, I just openned the my.cnf file looking for something that could help, but didn't actually modify anything. Today I woke up and found out that the was server connected to the database, and now I've verifed, and yeah it works completely. I'm not even connecting as localhost or 127.0.0.1 but I'm using the server's IP as the host parameter. dbHandler = dbConnect("mysql", "dbname=randomName;host=myVPS_IP", "username", "password", "share=1") All of a sudden it works.. this is strange. And to answer your question: When I commented that line I restarted the mysql server, not the whole VPS. (I'm using LAMP) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now