Skip to content
Advertisement

Execute node script in php from remote server

I have a web application that interacts with API. In html file is an element with onclick property for this function:

function executePHP() {
   $.ajax({
       type: "POST",
       url: 'index2.php',
   });

}

Then index2.php has written only this code:

<?php exec("/usr/local/bin/node script.js"); ?>

The script.js is just a file which is executed. Everything works fine on my maschine when using MAMP. However when I upload it on real server and open the website the script.js isn’t executed. And I didn’t forget to change the url for the real one once I was testing it. Any clues where the problem is?

Basically, I just need to execute node script.js when the button is clicked

Advertisement

Answer

After the discussion with an expert in this field I can answer my question. This code can’t be executed on basic shared server, therefore VPS (virtual private server) is needed.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement