If you are developing website but testing on localhost, what if you copy paste entire src into the ec2 instance and run it from there? Would that be creating a localhost inside ec2? Should I be developing in a way that I will not be using localhost on ec2? because ec2 itself is going to be a host? I feel like I'm kinda confused on concepts here.
Thanks
I was developing on local and then created ec2 and was testing what I developed and that hit me - It seemed a bit weird to run 'localhost' from ec2.
CodePudding user response:
When you say "testing on localhost", do you just mean that's what you type in your browser address bar?
The name localhost
is relative and just refers to the machine the code is running on. So if your code running on an EC2 instance uses localhost
, it would be connecting to itself, same as if it was running on your own machine.
Hardcoding any hostname in your code is probably a bad idea. Instead, consider using something like dotenv to configure these. This way, you can have one .env
file on your own machine and another on your host.