Solved:
I feel really novice now... and after I did all the installs etc to this new ec2 server I forgot to restart apache..... after getting the error message appeared with adding in the php code for ini_set display errors it said mysqli class wasn't found. So after further ado I double checked sqlnd was installed and performed the apache restart... now it works fine and echos what a disaster and so is my grammar.
I'm learning how to use php with mysql from Amazon's web service, and while I can connect the ec2 to rds db I cannot get a browser to echo the php code below, it simply aborts.
Configurations: EC2 server: php 8.0.16, apache 2.4.52, and mariadb 10.0.
RDS MySql DB: v8.0.28
For AWS networking:
The rds db is in a private subnet and the ec2 is in a public subnet.
Security policies:
Rds db:
Inbound connection only to Security group for the ec2 Outbound is all traffic for testing purposes.
Ec2:
Inbound is only set to my IP address Outbound set to all traffic for my testing purposes.
Everything is in the vpc group I made, and is a custom vpc.
I've been able to connect to the rds database from the ec2 amazon Linux instance via terminal.
example: mysql -h <server_name>.us-west-1.rds.amazonaws.com -u <username> -p
Outputs:
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 337
Server version: 8.0.28 Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> Ctrl-C -- exit!
Aborted
I can run, php TestOne.php in the terminal and it outputs that the connection is successful and closes the connection.
Example:
[linux_terminal_html]$ php TestOne.php
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
connected successfully to sql<br/>Our connection is ok!
closed connection successfully
</body>
</html>
The issue is the web browsers will not show the echo from the php code below and simply abort halfway through.
The network connection inspector in Chrome says it's an Internal error 500 for running the php file.
I'm not quite sure what step I need to do next.
Could someone explain to me what could be the issue?
Per Question below: DNS & Hostnames resolution is enabled on the vpc
External User via Browser Access: Port 80, public_ip/TestOne.php
My Code:
<!DOCTYPE html>
<html>
<body>
<h1>My first Test PHP page</h1>
<?php
$link = @new mysqli("<server_name>.us-west-1.rds.amazonaws.com","<user_name>","<password>","<db_name>");
//var_dump($link);
if ($link->connect_errno)
{
echo "failed to connect to sql";
echo "<br/>";
}
else
{
echo "connected successfully to sql";
echo "<br/>";
if ($link->ping())
{
printf ("Our connection is ok!\n");
}
else
{
printf ("Error: %s\n", $link->error);
}
if ($link->close()){
echo "closed connection successfully";
}
}
?>
</body>
</html>