php - Linux user apache has no permission to file which it owns
Get the solution ↓↓↓So I am trying to get shell_exec to give me the response of the program, but it is not giving me any response when I put it into echo. I have tried rewriting the output variable without a input variable, and have tried to produce errors hoping the error would give me some sort of output, but still nothing. Here is the code I am having issues with
<?php
$key = $_GET['key'];
$output = shell_exec("node totp.js ".$key."");
echo "Your output is = $output";
?>
Thanks!
Edit:
I tried defining where node is/usr/bin/node
and where the totp.js is/var/www/html/totp.js
and it gives an error in my log: No such file or directory. I took off everything other than trying to execute node, and I get the same no such file error. When I go back to what I had to begin with, I now get an error that command is not found, which was not appearing before. Is there a way to allow PHP to roam outside of the execution folder, I.E. the htdocs/html folder?
Edit 2: Tried changing permissions, chowning, discovered my PHP runs under the user apache, which now owns and has 755 permissions to my entire web folder, and now it recognizes the /usr/bin/node.... but it has no permissions. I have tried adding permissions in every possible way, I've tried giving it 777 although I knew I would not leave it at that, and it still has no permission to access it. I am clueless, and I guess this has become a linux issue rather than a php issue... lol - Also changing the title of the post as it is no longer a shell_exec issue, it is an issue with permissions
Edit 3: Something is royally wrong, it now gives 2 error messages. One is "No such file or directory" and the other is "Permission denied". It gives both, leading me to believe it is running on 2 seperate users/2 seperate locations. Idk what I should do, so I am going to reset my server as I have not done much, and start again. Saving the code first to see if that clears it up for me.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: illegal string offset
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.