Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

centos server running cakephp can't access remote mysql server but can access via pdo connect outside of cake

I can connect using the myslq commandline client using the same credentials and options. however when cake tries to connect to the remote server all I get is

Error: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'subdomian.domain.com' (13) requires a database connection

I tried running this

 GRANT ALL PRIVILEGES ON *.* TO 'myrootuser'@'webserver.domain.com' WITH GRANT OPTION;

This won't help me because I know I can connect via the cli

I can connect remotely from my home computers cake instance with no problems same host same credentials same everything

Yet my centos apache server running cake with all the right mysql packages installed can't connect

I am using the correct username password port everything and I keep getting that error

I have cleared tmp folders cache I used apc to clear cache I even restarted httpd

I have done everything. Nothing works.

I have event tried temporarily shutting off the firewall on both machines... no dice same error

I even tried creating a php file that just uses pdo to connect to the db and running it from the command line and it says Connected to Database !!

Why can't cake do it from cake. It can obviously work from a lone php file

I verified my creds and host over and over again

again I am able to connect using the exact same codebase on my local machine

so there has to be something like a mystery cake or centos apache thing going

I am also running APC Restarting mysqld and httpd doesn't change anything. I am at my wits end with this nonsense.

this is the php script I am testing with

$hostname = "my.dns.name.tohost";
$username = "myrootuser";
$password = "myrootuserpass";

try {
  $db = new PDO("mysql:host=$hostname;dbname=myDbSchemaName", $username, $password);
  echo "Connected to database";
}
catch(PDOException $e) {
  echo $e->getMessage();
}

// console output

Connected to database[root@localhost ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@localhost ~]# php connectInt.php
Connected to database[root@localhost ~]#

I even tried other ways in php I did a normal mysql connect script using the same credentails it can connect it can see all the databases.

[root@localhost ~]# php connectInt.php
information_schema
mydbname1
myotherdb
mysql
test

So cakephp doesn't like to connect to other linux servers in the same subnet without any firewall turned on yet any other php executed with the same credentials works. my local pc running the exact same code base talking to the same server works.

share|improve this question
    
seriously.. nobody has run into this. I would even accept a "blow away your stuff and reinstall comment at least" –  mugafuga Sep 23 '12 at 19:29
    
SOLUTION IS HERE YAY stackoverflow.com/questions/12548416/… –  mugafuga Sep 23 '12 at 19:55

1 Answer 1

In my case, Centos was block httpd making connection to MySQL.

Execute this

setsebool -P httpd_can_network_connect=1
share|improve this answer
    
This will allow any outbound network connection. If you don't need that, better to use httpd_can_network_connect_db instead, which only lets httpd connect to databases. –  Michael Hampton Mar 21 at 11:38
    
@MichaelHampton Thank you for the additional information –  William Notowidagdo Mar 24 at 1:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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