Cannot run PhantomJS with Flask on Ubuntu VPS Cannot run PhantomJS with Flask on Ubuntu VPS flask flask

Cannot run PhantomJS with Flask on Ubuntu VPS


Figure out the problem, current phantomjs and init.py don't have enough permission to manipulate the service.py of ghostdriver. Here is the fix:

  1. Add a new user: "add username", then set "add username sudo"
  2. Login to the new user, make sure every command you run from now on starts with "sudo"
  3. In your flask application where init.py resides, create "ghostdriver.log" and "phantomjs" which is an executable file.
  4. Chmod both of them to 777 : init.py, ghostdriver.log and phantomjs
  5. Set the custom config in init.py for phantomjs:

    br = webdriver.PhantomJS(service_log_path='./ghostdriver.log', executable_path='./phantomjs')

That's it, now your selenium + flask + phantomjs is now working correctly.