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?

php mysql aws

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Best MySQL DigitalOcean Performance – ScaleGrid vs. DigitalOcean Managed Databases

Compare ScaleGrid MySQL vs. DigitalOcean Managed Databases - See which offers the best MySQL throughput, latency, and pricing on DigitalOcean across workloads.

Category Subcategory Dropdown in PHP MySQL Ajax

PHP mysql dynamic dropdown list onchange. Here, we'll show how to populate category and subcategory in dropdown list using ajax in PHP mysql

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.

PHP MySQL Tutorial - User Registration System Using PHP & MySQL

In this PHP MySQL Tutorial, you'll learn how to create a user registration and login system using PHP and a MySQL database.

Hire Dedicated AWS Developer

Want to Hire AWS Developer for cloud computing services? At **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, we leverage maximum benefits from the AWS platform ensuring prominent Solutions for business requirements....