exec() and phantomjs issue with absolute paths

匆匆过客 提交于 2019-12-01 04:15:08

After a lot of searching and testing I got it to work with following additions:

//throws a lot of errors because searching some libraries
$cmd = 'unset DYLD_LIBRARY_PATH ;';
$cmd.= ' /abs/path/to/phantomjs';
$cmd.= ' /abs/path/to/script.js';

//set environment variable to node source
putenv('PATH=/abs/path/to/node/bin/');

//now exec the cmd and pipe the errors to stdout
exec($cmd.' 2>&1', $output);

//and output the results
print_r($output);

I'm not the best server admin, so I can not explain everything in detail, but the lines above generate an pdf. Yeah.

Preston S

I had a similar issue. PHP + PhantomJS Rasterize I found that phantomjs does not like running from an apache process. Try running your exec command from the command line:

php -r "exec('./phantomjs http://mywebsite.com/test.js', $o, $e); print_r($o); echo $e;"

If this works you have a few options:

1.) Some have suggested modifying sudoers to give no password sudo permissions for apache user to phantomjs binary

2.) Do like I did and run your script as a cron.

Try to place test.js in folder where test.php located (when calling exec('./phantomjs ./test.js', $o, $e);) or use full path.

I found the issue to be with selinux (which is now disabled by default on all production server builds as standard).

in file /etc/selinux/config find line containing:

SELINUX=

and change it to this:

SELINUX=disabled

run command (to take immediate effect without reboot)

/usr/sbin/setenforce 0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!