My development servers are external “dev.site.com”
We have our database on an external IP address, but there is no DNS records for it. DNS has been set up locally using hosts files.
For example: database.site.com 55.444.33.21
Since my external development server cannot resolve database.site.com or 55.444.33.21 independently, nor can I add local DNS records to the server, how can I properly access it?
Is there some method in PHP I can utilize to essentially create an on-the-fly DNS for?
I do not have the ability to change how anything is setup, but I have full control of the codebase which is PHP. Essentially, I’m looking for a way to say 55.444.33.21 = database.site.com in my script so whenever I call database.site.com in code it works.
EDIT
I am not able to access it with just the ip, and i cannot add it to the local hosts file on the server. My goal is to find a workaround to these issues.
Don’t call “database.site.com” in code.
Instead, define a constant in one place in the code and use that constant throughout the rest of the code:
or
Then throughout the code you’d use that constant instead of the actual value. So when you need to move the code to another environment, you configure it for that environment by changing the value of the constant:
or
In general, you want to use actual dynamic values as little as possible in the code. This gives all of your code multiple reasons to change. The value should be abstracted behind a constant or variable or symbol of some kind so that, if the value changes, only that one piece of code has a reason to change. The rest continues to function.