简体   繁体   中英

PHP shell_exec() cannot Run Node

shell_exec() work and return correct result for other commands. For example shell_exec('ls -a')

But it doesn't work and doesn't return anything for both shell_exec('node --version') or shell_exec('/usr/bin/node --version') .

I actually wanted to run a simple node script from PHP, but I can't even run node cli at all.

I am on Ubuntu 16.04 with Node 4.2.6 (installed from official repo) and XAMPP for Linux 5.6.12.

Any idea please? Do I need to set some permission on something?

<?php
session_start();
error_reporting(E_ALL);
ini_set("display_errors", 1);

?>

<!DOCTYPE html>
<html>
<head>    
</head>
<body>
<h2>Node Version</h2>
<?php
$output = shell_exec("node -v");
echo "<pre>$output</pre>";
?>
</body>

</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM