How to use PhantomJS 2.5.0 Beta on Heroku

2019-06-07 15:49发布

问题:

Version 2.5.0 beta of PhantomJS is available for use, but unlike stable versions, there are some dependencies for linux installations. I'm having trouble getting a working version on Heroku. I couldn't find a guide or any real answers in the Google group or elsewhere. How can I go about getting the installation?

回答1:

Ultimately, I was able to figure it out! There are a few things that you have to do...

TL;DR:

  1. heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt
  2. heroku buildpacks:add https://github.com/lookitsatravis/heroku-buildpack-phantomjs.git
  3. cat > Aptfile << EOL webp libhyphen0 https://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/gcc-5_5.4.1-8ubuntu1_amd64.deb https://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.4_amd64.deb EOL
  4. Commit Aptfile, push to Heroku app.

More info

  1. Dependencies: You have to use the Heroku Apt buildpack to install the missing dependencies. First, you need to add the buildpack to your app:

    heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt

    Next, you'll create a file in your project root called Aptfile. Here's where we add the missing dependencies for PhantomJS 2.5.0 Beta. 2.5.0 introduces webp support, so we need that. libhyphen0 is required as well, though I'm not sure how it us used. Finally, we use gcc-5 and the latest libstdc++6. Contents should look like this:

webp
libhyphen0
https://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/gcc-5_5.4.1-8ubuntu1_amd64.deb
https://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.4_amd64.deb
  1. PhantomJS: Next we grab the latest version of PhantomJS. I've created a fork of the most popular PhantomJS buildpack and updated it for use with 2.5.0 beta. 2.5.0 beta has builds for trusty as well as xenial, so the build pack will detect the Heroku stack and use the appropriate one (though the cedar-16 stack is still in beta at the time of this post). So, add it to your app:

    heroku buildpacks:add https://github.com/lookitsatravis/heroku-buildpack-phantomjs.git

  2. Deploy: All that's left is deployment! Commit the Aptfile to your repo, make sure the build packs are setup, and then push to Heroku.

Took a bit of trial and error, but ultimately I was able to get it up and running. Hope this helps others until the final candidate is released.