php - Set json file as environment variable
Get the solution ↓↓↓Please could I have step by step instructions to set the authentication.json file as environment variable instead of having the json file in my project location For example:
$jsonAuth = getenv('JSON_AUTH');
Running CentOS Linux 7.9.2009 with Apache
Answer
Solution:
Ideally, you want to encode the json to base 64. Its easier as base64 gets rid of the printable characters that need to be escaped. After that, you can do the following in PHP.:
$jsonAuth = json_decode(base64_decode(getenv('JSON_AUTH')), true);
Answer
Solution:
- Make sure you have mod_env installed (it usually is, but double check this).
- Find the
<VirtualHost>
for your application, and addSetEnv JSON_AUTH your_token_here
, and as many other auth variables you need to set. - Reload Apache (
apachectl -k graceful
or via init.d). - Read out the variables using
$jsonAuth = apache_getenv('JSON_AUTH');
.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: 403 this action is unauthorized.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.