2

In PHP running on Ubuntu, I can run exec('npm -v') and the output is good, but I can't run exec('gitbook xxxx').

gitbook is a npm package I installed by

npm install gitbook -g

I can run gitbook xxxx in the Ubuntu terminal, how can I run it from my PHP code?

2
  • try running sudo -u www-data npm -g install gitbook and see if that works Commented Aug 24, 2018 at 12:46
  • I've put the code and commands inside backticks so that it's clear which bits are the actual code and which bits are comments. Also capitalized words like PHP. Both to make it a little easier for the user to read. It might help if you add the execution results when you actually run the code. Commented Aug 24, 2018 at 13:10

2 Answers 2

4

If you run php by nginx or apache (for example, visit url example.com/index.php), sometime you need to export the PATH

exec("export PATH=/usr/local/bin && gitbook build);

after I added export PATH, everything works fine.

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

Comments

1

I tried once like this on UNIX-based OS:

You can run shell commands via the exec() function:

// make an php file to execute shell script

exec("node yourscript.js &", $output);

Well output here become array of each line of output along with process id. You can kill process by processid also.

exec("kill " . $processid);

This how I was did. Other then this you can use node supervisor. Hope it will help you. Try your also with node command.

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.