6

I'm trying to get PhantomJS to run via PHP.

When I run the JavaScript file directly through the command line, it works fine. When I run php render_html.php in the command line, which just runs an exec(), it works fine. However, when I try opening this php file in the browser, it does nothing. I don't even get anything back to echo.

I've done all this testing locally on OS X, and on my EC2 server, and I get the same result.

halfer
  • 19,824
  • 17
  • 99
  • 186
bearfriend
  • 10,322
  • 3
  • 22
  • 28
  • I know it's a ways back, but I'm having the exact same problem, but in CentOS. I assume the syntax of the sudoers file in CentOS would be different? – TomCDona May 28 '14 at 15:06
  • Hi there. I've moved your answer addendum to an answer proper, so people accessing Stack Exchange via the API get the correct Q/A separation. If you would like to make your own answer, please do, and I'll remove my own CW version. – halfer Dec 12 '14 at 21:49

3 Answers3

0

It might be a permission problem, check if the user running the web server has permission to run the phantomjs executable.

broesch
  • 2,442
  • 1
  • 19
  • 9
  • 1
    I did check the permissions on the executable itself. They were 755, which should be sufficient. Changed to 777, and still nothing. Thanks, though. – bearfriend Jun 26 '12 at 22:46
0

(Posted on behalf of the OP).

It does seem to have been a permissions issue. It seems that Apache may be treated a bit differently than other users? Even though the standard permissions would allow any user to access the PhantomJS application, apache still was unable.

Anyone with similar issues should read through this question and the answers.

Here is my slightly adapted solution for my specific case (on the Linux server). Edit your sudoers file (/etc/sudoers) to include the following line:

apache ALL=NOPASSWD: /usr/bin/phantomjs

I did this with emacs, (C-x C-q to enable editing of read-only file). I didn't seem to have any issues with that, but I guess using something called visudo is recommended for editing sudoers. Emacs worked for me, but you should look it up.

This gave the apache user explicit access to the PhantomJS app by giving it sudo access, limited to only the PhantomJS app.

Community
  • 1
  • 1
halfer
  • 19,824
  • 17
  • 99
  • 186
-1

I recently worked with phantomjs in centos 7 environment and faced same problem as op. I tried solutions and methods which I found in stackoverflow on top of each other, so I am not quite sure which method has worked or which methods has worked together to solve the problem. I tried

  1. giving 777 permission to phantomjs binary and target js and containing directory (did not work)
  2. visudo and giving permission to apache to use phantomjs with no password (did not work)
  3. added apache to sys group (did not work)
  4. disabled selinux after disabling selinux and restarting cent os, phantomjs started working in browser. :D :D