calling node and uglifyjs from Php context

2019-07-04 18:54发布

I'm trying out the JS minifier library UglifyJS2. I installed node.js on my mac using homebrew, and then uglifyjs through npm. It all works fine in the shell, node is found in the path and I manually added "uglifyjs" to the path so can find it just by typing "uglifyjs" (it is installed here: /usr/local/share/npm/lib/node_modules/uglify-js/bin/uglifyjs). This is done in ".bash_profile".

So, I can run everything fine in the terminal. I would now like to run it in a web context, in a Php page, using php's "exec". However, when I try to do that, exec returns status code '127', which I think means "command not found". I tried calling the complete path above too, but with the same result. My web server is running as the same user as i use in the shell.

The uglifyjs program starts like this, maybe that's a problem?

 #! /usr/bin/env node
 // -*- js -*-
 ...

Is there any way you know of to do this? Thanks

1条回答
祖国的老花朵
2楼-- · 2019-07-04 19:40

A symlink in "/usr/bin" did the job:

sudo ln -s /usr/local/bin/node node

查看更多
登录 后发表回答