We help IT Professionals succeed at work.
Get Started

"Can't connect to MySQL server" through php/apache but command line php works.

3,148 Views
Last Modified: 2013-12-12
I am trying to connect to a remote myql database server which is running centos 4.4 with mysql 5.0.27.

The website server is using apache (httpd 2.2.3), PHP 5.1.6 and Mysql Client API version 5.0.22.

Using a basic php script that does notthing but use mysql_connect to connect to the database server I get the following behaviour.

When run by accessing the php file through apache I get the error
"2003 : Can't connect to MySQL server on 'xx.xx.xx.xx' (13)"
where 2003 is the mysql_errno and the rest is mysql_error (I replaced my actal db server ip with xx for obvious reasons).

But If I run the same file from the command line "php connect.php" it connects to the db server no problem. As well if I run "mysql -h xx.xx.xx.xx -u ASDF -p" I can connect no problem as well. And just to be sure I have turned off iptables while trying to debug this problem.
I have setup a mysql db on the webserver and had no problem connecting to localhost... It is only a problem when trying to access a remote db server.

I have run the same php file from other servers and they have no problems connecting when run through apache (they have different centos versions but all 4 and above).

I have looked everywhere I can think to try and find some firewall like setting that is only active when running php/mysql through httpd but have come up empty. I hope there is just some simple httpd.conf setting that I have overlooked but at this point I am desperate to find it...

Thanks for reading.
Jamie
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 14 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE