Retrieving MySQL server credentials from concealed JSON file using PHP on AWS EB
I'm trying to implement the tutorial linked below [1] from AWS on my way to learn some PHP/MySQL. I'm very new to this.
Summarizing: The PHP application should retrieve a JSON file from a concealed folder (AWS S3 bucket) where the MySQL server credentials are described, then use it to login.
Thing is, it appears my code is aligned with the tutorial and also with all references I could find about this opperation, including at stack overflow. It seems the app is able to fetch the JSON file but somehow can't manage to retrieve the values.
JSON file content:
{
"address": "someaddress",
"port": "someport",
"database": "somedatabase",
"user": "someuser",
"password": "somepassword"
}
PHP partial code:
...
$json_file = file_get_contents('url.json');
$serverInfo = json_decode($json_file, true);
echo $json_file."<br />";
echo "Testing...<br />Server: ".$serverInfo["address"]."<br />";
$link = new mysqli($serverInfo["address"], $serverInfo["user"], $serverInfo["password"], $serverInfo["database"]);
...
The two ECHO calls where added to find out why connection at "$link..." was failing. The PHP output is this:
...
{ "address": "someaddress", "port": "someport", "database": "somedatabase", "user": "someuser", "password": "somepassword" }
Testing...
Server:
...
So, it seems to get the JSON fully, but the $serverInfo[*] functions don't return the values.
1: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.RDS.html#rds-external-credentials
php mysql json amazon-elastic-beanstalk
add a comment |
I'm trying to implement the tutorial linked below [1] from AWS on my way to learn some PHP/MySQL. I'm very new to this.
Summarizing: The PHP application should retrieve a JSON file from a concealed folder (AWS S3 bucket) where the MySQL server credentials are described, then use it to login.
Thing is, it appears my code is aligned with the tutorial and also with all references I could find about this opperation, including at stack overflow. It seems the app is able to fetch the JSON file but somehow can't manage to retrieve the values.
JSON file content:
{
"address": "someaddress",
"port": "someport",
"database": "somedatabase",
"user": "someuser",
"password": "somepassword"
}
PHP partial code:
...
$json_file = file_get_contents('url.json');
$serverInfo = json_decode($json_file, true);
echo $json_file."<br />";
echo "Testing...<br />Server: ".$serverInfo["address"]."<br />";
$link = new mysqli($serverInfo["address"], $serverInfo["user"], $serverInfo["password"], $serverInfo["database"]);
...
The two ECHO calls where added to find out why connection at "$link..." was failing. The PHP output is this:
...
{ "address": "someaddress", "port": "someport", "database": "somedatabase", "user": "someuser", "password": "somepassword" }
Testing...
Server:
...
So, it seems to get the JSON fully, but the $serverInfo[*] functions don't return the values.
1: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.RDS.html#rds-external-credentials
php mysql json amazon-elastic-beanstalk
I found out this file for some reason unknown to me downloads with a BOM (byte order mark). As a work-around I am using string operations to remove all characters before "{". Now it reads correctly. Maybe someone knows a systematic method for doing so?
– Insurecti
Jan 3 at 23:29
add a comment |
I'm trying to implement the tutorial linked below [1] from AWS on my way to learn some PHP/MySQL. I'm very new to this.
Summarizing: The PHP application should retrieve a JSON file from a concealed folder (AWS S3 bucket) where the MySQL server credentials are described, then use it to login.
Thing is, it appears my code is aligned with the tutorial and also with all references I could find about this opperation, including at stack overflow. It seems the app is able to fetch the JSON file but somehow can't manage to retrieve the values.
JSON file content:
{
"address": "someaddress",
"port": "someport",
"database": "somedatabase",
"user": "someuser",
"password": "somepassword"
}
PHP partial code:
...
$json_file = file_get_contents('url.json');
$serverInfo = json_decode($json_file, true);
echo $json_file."<br />";
echo "Testing...<br />Server: ".$serverInfo["address"]."<br />";
$link = new mysqli($serverInfo["address"], $serverInfo["user"], $serverInfo["password"], $serverInfo["database"]);
...
The two ECHO calls where added to find out why connection at "$link..." was failing. The PHP output is this:
...
{ "address": "someaddress", "port": "someport", "database": "somedatabase", "user": "someuser", "password": "somepassword" }
Testing...
Server:
...
So, it seems to get the JSON fully, but the $serverInfo[*] functions don't return the values.
1: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.RDS.html#rds-external-credentials
php mysql json amazon-elastic-beanstalk
I'm trying to implement the tutorial linked below [1] from AWS on my way to learn some PHP/MySQL. I'm very new to this.
Summarizing: The PHP application should retrieve a JSON file from a concealed folder (AWS S3 bucket) where the MySQL server credentials are described, then use it to login.
Thing is, it appears my code is aligned with the tutorial and also with all references I could find about this opperation, including at stack overflow. It seems the app is able to fetch the JSON file but somehow can't manage to retrieve the values.
JSON file content:
{
"address": "someaddress",
"port": "someport",
"database": "somedatabase",
"user": "someuser",
"password": "somepassword"
}
PHP partial code:
...
$json_file = file_get_contents('url.json');
$serverInfo = json_decode($json_file, true);
echo $json_file."<br />";
echo "Testing...<br />Server: ".$serverInfo["address"]."<br />";
$link = new mysqli($serverInfo["address"], $serverInfo["user"], $serverInfo["password"], $serverInfo["database"]);
...
The two ECHO calls where added to find out why connection at "$link..." was failing. The PHP output is this:
...
{ "address": "someaddress", "port": "someport", "database": "somedatabase", "user": "someuser", "password": "somepassword" }
Testing...
Server:
...
So, it seems to get the JSON fully, but the $serverInfo[*] functions don't return the values.
1: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.RDS.html#rds-external-credentials
php mysql json amazon-elastic-beanstalk
php mysql json amazon-elastic-beanstalk
edited Jan 3 at 21:45
Insurecti
asked Jan 3 at 5:44
InsurectiInsurecti
12
12
I found out this file for some reason unknown to me downloads with a BOM (byte order mark). As a work-around I am using string operations to remove all characters before "{". Now it reads correctly. Maybe someone knows a systematic method for doing so?
– Insurecti
Jan 3 at 23:29
add a comment |
I found out this file for some reason unknown to me downloads with a BOM (byte order mark). As a work-around I am using string operations to remove all characters before "{". Now it reads correctly. Maybe someone knows a systematic method for doing so?
– Insurecti
Jan 3 at 23:29
I found out this file for some reason unknown to me downloads with a BOM (byte order mark). As a work-around I am using string operations to remove all characters before "{". Now it reads correctly. Maybe someone knows a systematic method for doing so?
– Insurecti
Jan 3 at 23:29
I found out this file for some reason unknown to me downloads with a BOM (byte order mark). As a work-around I am using string operations to remove all characters before "{". Now it reads correctly. Maybe someone knows a systematic method for doing so?
– Insurecti
Jan 3 at 23:29
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016928%2fretrieving-mysql-server-credentials-from-concealed-json-file-using-php-on-aws-eb%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016928%2fretrieving-mysql-server-credentials-from-concealed-json-file-using-php-on-aws-eb%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I found out this file for some reason unknown to me downloads with a BOM (byte order mark). As a work-around I am using string operations to remove all characters before "{". Now it reads correctly. Maybe someone knows a systematic method for doing so?
– Insurecti
Jan 3 at 23:29