How to connect PHP to MySQL in private subnet VPC

How to connect PHP to MySQL in private subnet VPC

Hi I have two EC2 instances, one in a public subnet and one in a private subnet in my VPC.

Hi I have two EC2 instances, one in a public subnet and one in a private subnet in my VPC.

Web server (EC2) - public subnet
MySQL database (EC2) - private subnet

I am not using AWS RDS for the database, I am using EC2.

Here is my PHP code:

define ("DB_HOST", "");
define ("DB_USER", "dbuser");
define ("DB_PASS",'dbpassword');
define ("DB_NAME","dbname");
try {
    $dsn = "mysql:dbname=".DB_NAME.";host=".DB_HOST;
    $dbh = new PDO($dsn, DB_USER, DB_PASS);
    return $dbh;
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

What do I put in DB_HOST if the EC2 instance is on a private subnet?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

PhP MySQL Projects

Simpliv LLC, a platform for learning and teaching online courses. We basically focus on online learning which helps to learn business concepts, software technology to develop personal and professional goals through video library by recognized industry experts and trainers.

The Complete PHP MySQL Professional Course with 5 Projects

The Complete PHP MySQL Professional Course with 5 Projects

PHP Interview Questions with Solutions: Prepare for PHP Interview

Prepare for PHP Interviews. Set Variable With php.ini File. Logic & Output Behind PHP Code Segment. Class Concept, Error & Functions in PHP. Start PHP Now!