Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[How to] Unable run node js script under php (www-data can't run external program) #1862

Closed
Dolphin83 opened this issue Oct 30, 2018 · 3 comments
Labels

Comments

@Dolphin83
Copy link

Dolphin83 commented Oct 30, 2018

Info:

  • Docker version ($ docker --version): Docker version 18.06.1-ce, build e68fc7a
  • Laradock commit ($ git rev-parse HEAD): 436df88
  • System info (Mac, PC, Linux): Linux
  • System info disto/version: Ubuntu 18.04.1 LTS

Issue:

Unable run node js script under php

Expected behavior:

I should be able to run nodejs script under php

Relevant Code:

I have installed nodejs in workspace container

w1@linux:~/docker/laradock$ docker-compose exec -u laradock workspace bash
laradock@004db963f293:/var/www$ node -v
v10.10.0

When i try to run same under php it fails

use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

Route::get('/test', function () {
    $p = new Process('node -v');
    $p->run();
    if (!$p->isSuccessful()) {
        dump( new ProcessFailedException($p));
    } else {
        dump($p->getOutput());
    }
});

Output:

ProcessFailedException {#462 ▼
  -process: Process {#459 ▶}
  #message: """
    The command "node -v" failed.\n
    \n
    Exit Code: 127(Command not found)\n
    \n
    Working directory: /var/www/foo.local/public\n
    \n
    Output:\n
    ================\n
    \n
    \n
    Error Output:\n
    ================\n
    sh: 1: node: not found\n
    """
  #code: 0
  #file: "/var/www/foo.local/routes/web.php"
  #line: 44
  trace: {▶}
}

Let's find out which user performs code

Route::get('/test', function () {
    $p = new Process('whoami');
    $p->run();
    dump($p->getOutput());
});

Output:

"www-data\n"

So, user "www-data" does not know anything about installed node js

How i can fix it?

@vv12131415
Copy link
Contributor

Hi!

The problem is not in the user www-data.

See what happens - you have installed the node under the workspace container
and you're checking if it is there by node -v

but the requests are by other container called php-fpm. And in the php-fpm you don't have node installed

So you should install node there - see the example in dockerfile of workspace

RUN if [ ${INSTALL_NODE} = true ]; then \
# Install nvm (A Node Version Manager)
mkdir -p $NVM_DIR && \
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install ${NODE_VERSION} \
&& nvm use ${NODE_VERSION} \
&& nvm alias ${NODE_VERSION} \
&& if [ ${NPM_REGISTRY} ]; then \
npm config set registry ${NPM_REGISTRY} \
;fi \
&& if [ ${INSTALL_NPM_GULP} = true ]; then \
npm install -g gulp \
;fi \
&& if [ ${INSTALL_NPM_BOWER} = true ]; then \
npm install -g bower \
;fi \
&& if [ ${INSTALL_NPM_VUE_CLI} = true ]; then \
npm install -g @vue/cli \
;fi \
&& ln -s `npm bin --global` /home/laradock/.node-bin \
;fi

@stale
Copy link

stale bot commented Feb 2, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale label Feb 2, 2020
@stale
Copy link

stale bot commented Feb 23, 2020

Hi again 👋 we would like to inform you that this issue has been automatically closed 🔒 because it had not recent activity during the stale period. We really really appreciate your contributions, and looking forward for more in the future 🎈.

@stale stale bot closed this as completed Feb 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants