0

I have two EC2 instance; my 1st EC2 instance is for my projects; my 2nd EC2 instance for the database

Is it possible to call the other EC2 in my .env file coming from my 1st EC2 instance?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Angel
  • 966
  • 4
  • 25
  • 60
  • You might want to look for this: [Connect to mysql on Amazon EC2 from a remote server](https://stackoverflow.com/questions/9766014/connect-to-mysql-on-amazon-ec2-from-a-remote-server) – Arpit Jain Mar 24 '23 at 05:35

1 Answers1

0

You will need to specify the IP address of the second EC2 instance in the first instance. You can find the IP address in the AWS console or by running a command such as ifconfig or ipconfig.

Add in .env file.

DB_HOST=10.0.0.2 # IP address of your second EC2 instance
DB_PORT=3306     # port number of your database
DB_USER=database_username # your database username
DB_PASS=database_password # your database password

Let me know if this working or not.

Hitesh Padhara
  • 434
  • 3
  • 4
  • is it the ipv4 address? – Angel Mar 24 '23 at 05:06
  • When I changed the DB_HOST=, it gives me an error "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. " – Angel Mar 24 '23 at 05:18
  • Yes. it was Ipv4 address. – Hitesh Padhara Mar 24 '23 at 05:18
  • It gives me an error "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. " – Angel Mar 24 '23 at 05:20
  • It might be possible to change the security group settings or DNS lookup issues. – Hitesh Padhara Mar 24 '23 at 05:57