node.js - PHP-CGI Called from NodeJS Always Returns 404
Get the solution ↓↓↓Solution:
I could replicate it on my Mac and found a way that seems to solve the issue.
As of why this happens, this source has a good explanation:
If you are using nginx with php-cgi and have followed the standard procedure to set it up, you might often get the “No input file specified” error. This error basically occurs when the php-cgi daemon cannot find a .php file to execute using the SCRIPT_FILENAME parameter that was supplied to it. I’ll discuss about the common causes of the error and it’s solutions.
Of course, you are not using nginx, but I think it applies here as well.
So following the advice from the article to adjust the code to make use ofSCRIPT_FILENAME
worked for me:
child_process.exec("php-cgi",{
env: {
REQUEST_METHOD: method,
CONTENT_LENGTH: body.length,
QUERY_STRING: query,
REDIRECT_STATUS: true,
SCRIPT_FILENAME: '/home/user/test.php'
}
}, function (error, stdout, stderr) {
if (error) {
if (displayErrors && stdout) {
callback(stdout);
} else {
callback(error);
}
} else if (stdout) {
console.log(stdout);
callback(null, stdout);
} else if (stderr) {
callback(stderr);
} else {
callback(null, null);
}
});
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: npm err! code 1
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.