PhantomJS does not work in PHP through the browser (but through the command line and even running PHP through the command line)

I am trying to run PhantomJS through PHP.

When I run the JavaScript file directly through the command line, it works fine. When I run php render_html.php on the command line, which just runs exec (), it works fine. However, when I try to open this php file in a browser, it does nothing. I won’t even get back to echo.

I tested this locally on OS X and on my EC2 server and get the same result.

+6
source share
3 answers

This may be a permission issue, check if the user running the web server has permission to run the phantomjs executable.

0
source

(Sent on behalf of OP).

This seems to be a permissions issue. It seems that Apache can be viewed somewhat differently than other users? Despite the fact that standard permissions will allow any user to access the PhantomJS application, apache still could not.

Anyone who has similar problems should read this question and answers .

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

 apache ALL=NOPASSWD: /usr/bin/phantomjs 

I did this with emacs (Cx Cq to enable read-only file editing). I had no problems with this, but I suggest that for editing sudoers it is recommended to use something called visudo. Emacs worked for me, but you should look at it.

This gave the apache user explicit access to the PhantomJS application, giving him access to sudo, limited only to the PhantomJS application.

0
source

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

  • gives 777 permission to binary and target js phantomjs and contains directory (doesn't work)
  • visudo and apache permission to use phantomjs without password (doesn't work)
  • added apache to sys group (doesn't work)
  • selinux is disabled after disconnecting selinux and rebooting cent os, phantomjs started working in the browser .: D: D
-1
source

Source: https://habr.com/ru/post/919076/


All Articles