0

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>
Novice
  • 11
  • 1
  • Did you enable name resolutions for your VPC? Is it custom VPC? Your question lacks details and is unclear. – Marcin Apr 24 '22 at 22:27
  • @Marcin "Everything is in the vpc group I made.", correct it is a custom vpc it is not default, and yes name resolutions were enabled as I made the VPC. – Novice Apr 25 '22 at 05:11
  • Just a bit of logic: it's no use to post the code that *works* for you; it's quite peculiar to add the *error suppression operator* (@) when you're trying to find out what the error is. – Your Common Sense Apr 26 '22 at 03:51
  • Indeed, it would be logical if it did output a page error but sadly it doesn't for me. And editing the php.ini wasnt allowing me due to the permission error, hence where I turned to asking a question of what to do next. I apologize for my noviceness in this matter. I'll look into the link to see more of how to allow error reporting. Thank you for giving me the next tool to fixing this issue. – Novice Apr 26 '22 at 04:30
  • With php.ini or not, but you need to get the error message. Without the error message you will never know what causes the 500 error. you may want to check the error log. – Your Common Sense Apr 26 '22 at 04:56
  • Thank you, I added my noviceness solution up top. And I'm still learning where the php logs are and will make sure I find that out. – Novice Apr 26 '22 at 05:01
  • I would say you performed much better than 99% of novices here. Keep it up! – Your Common Sense Apr 26 '22 at 05:28

0 Answers0