Can't connect from EC2 to RDS via PHP. I can directly thought

5,971

I found a similar issue.

The solution was to run setsebool -P httpd_can_network_connect=1

Share:
5,971

Related videos on Youtube

jackreichert
Author by

jackreichert

Full-stack developer. Philosophy major. Team builder, engineering web applications, professionally, full time for over a decade. Demonstrated commitment to optimizing, refactoring and perfecting every aspect of the stack from UX, and typography to optimizing algorithms, and wrangling servers.

Updated on September 18, 2022

Comments

  • jackreichert
    jackreichert over 1 year

    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 'XXXX.xxxxxxx.us-east-1.rds.amazonaws.com'

    This is my first time working with both.

    Am I missing something here?

    define("HOST", "XXXX.xxxxxxx.us-east-1.rds.amazonaws.com");
    define("DBUSER", "my_user");
    define("PASS", "********");
    define("DB", "mydb");
    define("PORT", 3306);
    
    $link=mysqli_connect(HOST,DBUSER,PASS,DB,PORT); 
    
    // Check connection
    if (mysqli_connect_errno($link)){
        echo "Failure to connect: " . mysqli_connect_error();
    }
    
    mysqli_close($link);
    
    • jamieb
      jamieb about 11 years
      What is the complete command you are entering at the shell prompt?
    • jamieb
      jamieb about 11 years
      You're not specifying a database in that command. Are you sure it's the entire command?
    • jackreichert
      jackreichert about 11 years
      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"
    • bahamat
      bahamat about 11 years
      Try connecting with the database. Your user probably hasn't been given specific permission to access that database.