/    Sign up×
Community /Pin to ProfileBookmark

php remote mysql connection

hi everyone,
sorry if this is posted in the wrong forum, but it’s kinda a php and mysql issue. I have a mysql database on a remote server. I setup my servers and mysql users to be able to connect remotely. it worked great until a few days ago when it stopped working and started throwing me an error:

[CODE]
Could not connect: Can’t connect to MySQL server on ‘XXX.XX.XXX.03’ (13)
[/CODE]

database server IP ends in .03
websites server ends in .02

so what is really interesting is I can still log into the database from the remote server ie:

[CODE]
## from the remote .02 server ##

mysql -h XXX.XX.XXX.03 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 74
Server version: 5.0.77 Source distribution

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql>
[/CODE]

what is even more interesting is that the script that is giving me the error above can be run from the command line with no problems on the remote (.02) server. script below:

[code=php]

$link = mysql_connect(‘XXX.XX.XXX.03’, ‘root’, ‘MYPASSWORD’);
if (!$link) {
die(‘Could not connect: ‘ . mysql_error());
}
echo ‘Connected successfully’;
mysql_close($link);

[/code]

so basically if I hit the above code with a browser I get this error: Could not connect: Can’t connect to MySQL server on ‘XXX.XX.XXX.03’ (13)

but if I log into the remote .02 server and enter:

[CODE]
php /var/www/html/test.php

# i get:
Connected successfully

[/CODE]

very strange I’m thinking permissions issue but I don’t really know. any help would be appreciated. – thanks.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@svidgenSep 03.2010 — Strange. Is this a shared hosting environment? Were any updates installed recently?

What php versions are out there? The PHP command line parser may be running a different version than the apache module -- which incidentally could have been accidentally updated without the mysql option.
Copy linkTweet thisAlerts:
@bpdpauthorSep 03.2010 — Thanks for the reply svidgen. that was a good thought, but i ran:
[CODE]
php --version
PHP 5.1.6 (cli) (built: Jan 13 2010 17:09:42)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
[/CODE]


and I'm getting the same version in a phpinfo() file that I just uploaded. In the info file I am also showing the mysql module.

These are actually dedicated servers, no updates that I know of.
Copy linkTweet thisAlerts:
@svidgenSep 03.2010 — Thanks for the reply svidgen. that was a good thought, but i ran:
[CODE]
php --version
PHP 5.1.6 (cli) (built: Jan 13 2010 17:09:42)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
[/CODE]


and I'm getting the same version in a phpinfo() file that I just uploaded. In the info file I am also showing the mysql module.

These are actually dedicated servers, no updates that I know of.[/QUOTE]


Strange. So ... the apache module is PHP 5.1.6 and includes the mysql in its config string. Yeah, I'm at a loss. I'm assuming you've already tried the "silly" solutions like restarting apache and mysqld.

Umm ... check your httpd error log. Look for socket errors?

Sorry ... shots in the dark here. I recall having an issue once wherein PHP/Apache was looking for the mysqld socket in the wrong place by default. The solution for this is, if it turns out the be the issue, is one of three:

Create an alias for the socket.

Change the socket location mysql uses. (don't recall how to do that)

Change the mysql socket setting in php.ini and restart apache.

I can give it some more thought if that's not the issue. But, I think I'll be as much at a loss as you if that doesn't do it ...
Copy linkTweet thisAlerts:
@bpdpauthorSep 03.2010 — weird, found it had to do with SELinux. had to run:
[CODE]
sudo /usr/sbin/setsebool -P httpd_can_network_connect=1
[/CODE]


on all my servers. now I back up and running. Have no idea why the settings changed all the sudden.
Copy linkTweet thisAlerts:
@svidgenSep 04.2010 — Interesting. I'm glad you got it figured out.
×

Success!

Help @bpdp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...