0
votes

Hi I am trying to host PHP code in AWS EC2(Windows) server on IIS. I am able to host the php webpages but the issue is the the webpages are not able to communicate to AWS RDS. PHP Code for Database:

<?php
$con=mysqli_connect("mysqldatabase.xxxxxxxxxx.ap-south-1.rds.amazonaws.com", "admin", "xxxxxxx", "detsdb", "3306");
if(mysqli_connect_errno()){
echo "Connection Fail".mysqli_connect_error();
}

  ?>

I am using default VPC rule and in both RDS and EC2 Security Group(Both Inbound and Outbound) I have opened all traffic as well as Opened SG id with port 3306 with each other.

**Error on Webpage: Connection FailServer sent charset unknown to the client. Please, report to the developers ** Error Image

When I am trying the same code from my personal computer, I am able to communicate with RDS. I am using Wamp server to communicate and host it locally.

written a simple code to test the functionality that's also working:

<?php
$con = mysqli_connect("mysqldatabase.xxxxxx.ap-south-1.rds.amazonaws.com", "admin", "xxxxx", "detsdb", "3306");
if($con){
echo "Connection Success";
}
else
{
    echo "Error";
}

?>

Success Connection

Please help me on this.

Ec2 SG Ingress

EC2 SG Outbound

RDS SG Ingress

RDS SG Outbound

Edit: Screenshot attcahed for both Ec2 and RDS SG

3
Is the database set to Publicly Accessible = True? Is the EC2 instance in a public or a private subnet? Does the VPC have a NAT Gateway?John Rotenstein
@JohnRotenstein yes Database is set Publicly Accessible = True, EC2 instance in a public subnet, No The VPC doen't have the NAT Gateway, I am using default VPC rules.Manish Parida
@JohnRotenstein my DB an EC2 both are in public subnet, then I don't think so I need NAT Gateway.Manish Parida
One problem might be that, since the database is publicly accessible, the DNS Name resolves to a public IP address. This means that the EC2 instance goes to the public IP address of the database, and its traffic comes from the public IP address of the EC2 instance. This impacts the security group, since traffic is from a public IP address rather than from the instance itself. Please edit your question to show your Security Group configuration.John Rotenstein

3 Answers

0
votes

On the windows server make a .txt file, then rename the extension to .UDL open the file and use it as a quick way to test the connection.

Next follow this fix: PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers

If this fails create a second RDS DB in a private subnet and test John's advice about DNS resolving to private IP using the UDL file.

0
votes

Go to the server and try to connect RDS directly and check whether you can able to access or not.

0
votes

Basically Its a parameter group issue: so what i did was: Created a new Parameter group and then edited them. Searched all character-set parameters. These are blank by default. edit them individually and select utf8 from drop down list. character_set_results, character_set_server and SAVE. Now you can able to connect