0

I have an apache web server running PHP. I am trying to make a connection from apache server to a database server running mysql server. Heres a run down of the settings in place.

  • apache server: RHEL 5.5; PHP 5.3.2
  • database server: Ubuntu 10.04 64bit; mysql server version 5.1
  • There are no firewall rules restricting connections between these two machines. neither in our hardware firewall or in iptables.
  • /etc/mysql/my.cnf has the bind-address set to the machine's ip.
  • skip-networking is commented out, ie disabled.
  • mysql is running and on the standard port 3306
  • /var/run/mysqld/mysqld.sock is owned by mysql
  • i can connect to mysql locally

the following is my php connection script:

<?php

$host="555.555.55.55";
$user="some_user"; 
$pass="some_pass";   

$conn = mysql_connect($host, $user, $pass);

if ($conn === FALSE) { echo mysql_error(); } 
else { echo 'Connected'; mysql_close($conn); }

?>

attempting to execute the php script in a browser hosted on the apache server only yields: "Could not connect: Can't connect to MySQL server on '555.555.55.55' (4)"

any suggestions? Thanks.

  • have you tried connecting to the remote mysql server with command-line tools yet? I would do that first to isolate it to msql problems or php implementation problem....on the RHEL box use mysql -u--------whatever command to connect directly to the remote database to isolate the problem – RobotHumans Nov 11 '10 at 15:14
  • Do you still have the problem. Have you found how to solved the problem or considered accepting an answer that solves your problem (if any)? – Luis Alvarado Dec 5 '11 at 18:57
  • This appears to be abandoned – Marco Ceppi Dec 5 '11 at 19:13
1

We changed the ip of the machine to a different ip range within our institution. from a private range to a public ip. it now connects. We're now investigating this private range. Thanks for everyones help!

https://serverfault.com/questions/200774/apache-server-a-attempts-conn-to-mysql-server-b-times-out-what-am-i-missing/201308#201308

0

Just to rule simple things out, have you tried running ps -A | grep mysqld on the Ubuntu server? If there is no text output here, the server is not actually running.

Can you connect to the MySQL server by running mysql -u root -p from a terminal on the Ubuntu machine? If so, can you also connect using mysql -u root -p -h <ubuntu-server-ip> from your Red Hat server?

Your PHP script seems fine, though for what it's worth you will typically want to make a more explicit comparison when checking your $conn variable, like:

if ($conn === FALSE) { echo mysql_error(); } else { echo 'Connected'; }

Also, if $conn is set to FALSE, calling mysql_close($conn) at the bottom is a waste of server time (mysql_close(FALSE) will take up time to return FALSE silently); you only need to free a valid resource identifier, and in this case (a non-persistent connection) you don't need to explicitly free the resource anyway.

  • I forgot to mention. I can connect to mysql locally with "mysql -u root -p". Also "ps -A | grep mysqld" does list a process for the server. – ifeltalive Nov 11 '10 at 14:51
  • Thanks for the PHP tips! mysql -u root -p -h <ubuntu-server-ip> from redhat yields: "ERROR 2003 (HY000): Can't connect to MySQL server on '<ubuntu-server-ip>' (110)" – ifeltalive Nov 11 '10 at 14:56
  • MySQL server on '<ubuntu-server-ip>' (110) makes it look like it is trying to connect on the wrong port...not a php guy though so I really can't say 100% – RobotHumans Nov 11 '10 at 15:15
  • Ah, I'm sorry I didn't mention, you need to replace <ubuntu-server-ip> with the IP of your Ubuntu server. And happy to help regarding the PHP. – ayan4m1 Nov 11 '10 at 15:34
  • heh, thanks, i knew what you meant, ie the ip was changed. – ifeltalive Nov 12 '10 at 15:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.