Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've set up an EC2 instance it has mysql and php-mysql installed (not mysql-server).

I've set up an RDS instance and set the security group to the EC2 instance.

I can connect via the command line from the EC2, but when I try connecting via mysqli I get the message: Can't connect to MySQL server on ''

This is my first time working with both.

Am I missing something here?

define("HOST", "");
define("DBUSER", "my_user");
define("PASS", "********");
define("DB", "mydb");
define("PORT", 3306);


// Check connection
if (mysqli_connect_errno($link)){
    echo "Failure to connect: " . mysqli_connect_error();

share|improve this question
What is the complete command you are entering at the shell prompt? – jamieb Apr 1 '13 at 4:07
mysql -h -P 3306 -u my_user -p – jackreichert Apr 1 '13 at 4:13
You're not specifying a database in that command. Are you sure it's the entire command? – jamieb Apr 1 '13 at 4:14
Yeah, it didn't connect to a specific DB but I WAS able to connect to the RDS server. However if I try the same via mysqli I'm getting "can't connect to server" – jackreichert Apr 1 '13 at 4:17
Try connecting with the database. Your user probably hasn't been given specific permission to access that database. – bahamat Apr 1 '13 at 6:22
up vote 2 down vote accepted

I found a similar issue.

The solution was to run setsebool -P httpd_can_network_connect=1

share|improve this answer
this works!! thanks you very much – Shany G Aug 16 '15 at 13:09

I had to make changes for SELinux, my instance was RHEL6.

setsebool httpd_can_network_connect=1 setsebool httpd_can_network_connect_db on

What I found odd was that SELinux logged nothing unusual to /var/log/audit/audit.log

share|improve this answer

Your Answer


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.