2

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

23
  • 2
    Your code is ok, however basic shared servers don't allow this. You need a real real server vps. Commented Nov 21, 2020 at 19:36
  • 1
    Oh I see, unfortunately these services are quite expensive Commented Nov 21, 2020 at 20:26
  • 1
    Yeah, I think this will be good invention. Once I have it, can I use my old code and it will work? Commented Nov 21, 2020 at 20:35
  • 1
    I am quite newbie in this type of backend and executing command, so I am sorry for asking so much. The fact is, I am using Webstorm as my IDE and when I open it from there it doesn't work, but I have also Mamp on my computer and with that everything works. I was just checking the servers now and there is huge variety of them. Which one would you advise for a beginner, who was used to only to Mamp? Commented Nov 21, 2020 at 20:50
  • 1
    Hey, you there? Commented Nov 29, 2020 at 16:56

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.