Page 1 of 1

mysql uses ip address

PostPosted: 31. December 2016 20:37
by oldyork
Op - feel free to nuke the post. I didn't see an English version of the mysql list so I decided to take liberties.

I have an Apache server running as a virtual host. I'm trying to replicate a production environment on my local box. Works well, except for the site's use of mysql database connectors; they hard coded the host parameter as an ip address and not a name. Is there a way to accommodate the use of an ip address in the mysql? This is deprecated technology [ mysql_connect('123.123'123.123', $db_user, $db_pw) - I had to install the support module ] so there may be additional problems.

Xampp port is ApacheFriends XAMPP Version 5.6.15

Thank you

Re: mysql uses ip address

PostPosted: 31. December 2016 22:11
by JJ_Tagy
I'm pretty sure you can use ip or host. You probably want to make sure you use all dots (.) instead of '123.123'123.123'

Also, you will want to use mysqli instead of mysql to connect.

Re: mysql uses ip address

PostPosted: 01. January 2017 03:30
by oldyork
Typo on the ip address. Sorry.

So, here's some more info. I've modified two files trying to remap the ip address.

\Windows\System32\drivers\etc\hosts
and
\xampp2\apache\conf\extra\httpd-vhosts.conf

With host names it worked find. Here are the additional entries I made. If you can think of a permutation, I've probably tried it. I'm wonder now it this isn't some mysql config problem. Again, take away the ip address, use a name, and everything is fine: (it's the entries with the ip addresses that fail. After any change in either of these two files, I cycled Apache and flushed the dns. Error message from connect attempt is:

mysql_connect(): A socket operation was attempted to an unreachable host

======================================================================

<VirtualHost *:80>
DocumentRoot "C:/xampp2/htdocs"
ServerName www.production.com
</VirtualHost>

<VirtualHost 123.123.123.123>
DocumentRoot "C:/xampp2/htdocs"
ServerName www.production.com
</VirtualHost>

====================================================================

127.0.0.1 localhost
127.0.0.1 www.mspfound.com # second server
123.123.123.123 localhost

or


127.0.0.1 localhost
127.0.0.1 www.mspfound.com # second server
123.123.123.123 www.mspfound.com

Re: mysql uses ip address

PostPosted: 01. January 2017 03:57
by Altrea
domain name resolution is a one way ticket. You can only resolve a name to an ip address, not an ip address to a name.
You cannot simulate that your computer does have a foreign ip address except you really configure your network card to have this ip address.

Re: mysql uses ip address

PostPosted: 01. January 2017 04:10
by oldyork
You know I'm in no position to doubt you, and yet... it's software! :-) I am proceeding with some edits to obviate the need. However, I'll just mention that I see all kinds of virtual ip posts out there - none of which I can truly understand yet. But thank you and please don't take this post in the wrong way. I discuss with all respect here. Thank you for your input. I'd REALLY like to find a good link on this server/ip/dns stuff. I thought I knew enough. I surely don't.

Re: mysql uses ip address

PostPosted: 01. January 2017 12:30
by Nobbie
oldyork wrote:I'd REALLY like to find a good link on this server/ip/dns stuff. I thought I knew enough. I surely don't.


As your code is working with hard coded IPs, there is no DNS involved. DNS is a service to assign domain names to IPs. But IPs are IPs and Altrea is completely right, you MUST assign the IP (i.e. 123.123.123.123) to the network adapter which should run the server. There is no other way - or you have to edit the corresponding files and replace the hard coded IP either by another IP or by a name.

Re: mysql uses ip address

PostPosted: 01. January 2017 17:12
by oldyork
Happy New Year! Thanks for the post. My resolution for the year is network 101 and understand what is being said here. York - out.

http://httpd.apache.org/docs/2.4/vhosts/ip-based.html

Re: mysql uses ip address

PostPosted: 01. January 2017 18:01
by Nobbie


IP Based VirtualHosts do not help on your issue.

Re: mysql uses ip address

PostPosted: 01. January 2017 18:47
by Altrea
The question i am asking is, why do you need to use a different ip address?
Why don't you simply use your own one or a simulated domain name as everyone?