Uglify-JS won't run using shell_exec()

My question is similar to this:

Nodejs - .node_libraries/ for www-data

I've been trying all night to get php to execute uglifyjs. I've tried:

die(shell_exec('NODE_PATH="/home/app/nodejs/node_modules/"; export NODE_PATH; uglifyjs -o /home/app/public_html/js/profile.min5.js /home/app/public_html/js/profile.js'));

and

die(shell_exec('node /home/app/nodejs/node_modules/uglify-js/bin/uglifyjs -o /home/app/public_html/js/profile.min33.js /home/app/public_html/js/profile.js'));

and a bunch of other crazy combinations but nothing works. Everything works fine if I do it manually in the shell. Can anyone help please?

Have you tried looking at the following (I'll go for the obvious since you haven't said what you've already tried):

user apache/www-data is allowed access to /home/app : sometimes /home directories are closed off (chmod 0700)

Is safe_mode on your server in effect? From the command line, try:

php -i | grep safe_mode

Then, look at the output of:

phpinfo();

Which version of PHP are you using (might well be irrelevant)?