I try to execute a node.js file from php with shell_exec() but then the script returns an error. It works fine when i start it from commandline.
index.php (ajax call to php)
function calc(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("test1").innerHTML = this.responseText;
}
};
xhttp.open("GET", "php/myNodeCall.php", true);
xhttp.send();
}
php/myNodeCall.php
$test = shell_exec('node /volume1/web/myNode/app.js');
echo "<br>".$test."<br>";
app.js (config.filename = test0.json)
fs.writeFile(config.filename, JSON.stringify(myContent), {}, function(err) {
if (!err) {
console.log('content written to ' + config.filename + '!');
} else {
console.log(err);
}
});
The return is the following error message:
{ [Error: EACCES: permission denied, open '/volume1/web/myNode/test0.json'] errno: -13, code: 'EACCES', syscall: 'open', path: '/volume1/web/myNode/test0.json' }
When executed from bash, the script creates a new file with the given name and myContent. So how/where do i have to give permission to let app.js create/open the file also when it was executed from php?
via Dario Eberhard
No comments:
Post a Comment