Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install WKHTMLTOX (WKHTMLTOPDF + WKHTMLTOIMAGE) on AWS ElasticBeanstalk

I need WKHTMLTOX to be installed with my AWS EB app. I found this tutorial and it works except it supports old version.

Did anyone install the latest (0.12.3) version on AWS EB as this is a bit different folders structure?

like image 202
Strabek Avatar asked May 18 '16 07:05

Strabek


5 Answers

None of the other answers appear to be fully function at the moment (some because the links are no longer valid and some because of new dependency issues). I don't have enough reputation to comment on Lucas D'Avila's answer so here is the solution that is working for me today with Amazon-Linux/2.9.7:

Create an .ebextensions file named something like .ebextensions/wkhtmltopdf.config

container_commands:
    1_install_wkhtmltopdf:
        command: yum -y install fontconfig libXrender libXext xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi freetype libpng zlib libjpeg-turbo openssl icu
        ignoreErrors: true

    2_install_wkhtmltopdf:
        # see: https://wkhtmltopdf.org/downloads.html for updates
        command: wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz --dns-timeout=5 --connect-timeout=5 --no-check-certificate
        test: test ! -f .wkhtmltopdf

    3_install_wkhtmltopdf:
        command: tar -xJf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
        test: test ! -f .wkhtmltopdf

    4_install_wkhtmltopdf:
        command: cp wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
        test: test ! -f .wkhtmltopdf

    5_install_wkhtmltopdf:
        command: cp wkhtmltox/bin/wkhtmltoimage /usr/local/bin/wkhtmltoimage
        test: test ! -f .wkhtmltopdf

    6_install_wkhtmltopdf:
        command: touch .wkhtmltopdf
like image 83
Elric Pedder Avatar answered Nov 13 '22 07:11

Elric Pedder


Complementing Elric Pedder anwser.

If wkhtmltopdf is already installed, it will give and error because yum will give a "Error: Nothing to do" and exit with -1 state. This will occur when you re deploy your elastic beanstalk.

In order to install wkhtmltopdf without failing, i check if is already installed.

wkhtmltopdf.config

container_commands:
    01_install_wkhtmltopdf:
        command: sudo yum -q list installed wkhtmltox.x86_64 &>/dev/null && sudo yum -y reinstall https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.amazonlinux2.x86_64.rpm || sudo yum -y install https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.amazonlinux2.x86_64.rpm
like image 44
Francisco Javier Sucre Gonzále Avatar answered Sep 22 '22 10:09

Francisco Javier Sucre Gonzále


After trying different tutorials, including this I finally got this working - I updated porteaux's answer.

I added below code to my EB *.config file in commands section:

commands:
  # install WKHTML
  03_command:
    command: yum install xz urw-fonts libXext openssl-devel libXrender
  04_command:
    command: wget http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
  05_command:
    command: tar -xJf wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
  06_command:
    command: cp wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
  07_command:
    command: cp wkhtmltox/bin/wkhtmltoimage /usr/local/bin/wkhtmltoimage
  1. The above tutorial is for Ubuntu and AWS EB runs Amazon Linux so they use yum instead of apt-get
  2. I had to use J switch with tar command to deal with *.xz file
  3. Finally I had to copy both wkhtmltopdf and wkhtmltoimage files to bin folder.

Done! I hope this will help others.

UPDATE: as per dhollenbeck suggestion

 04_command:
      command: wget https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
      test: test ! -f .wkhtmltopdf
 05_command:
      command: tar -xJf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
      test: test ! -f .wkhtmltopdf
 06_command:
      command: cp wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
      test: test ! -f .wkhtmltopdf
 07_command:
      command: cp wkhtmltox/bin/wkhtmltoimage /usr/local/bin/wkhtmltoimage
      test: test ! -f .wkhtmltopdf
 08_command:
      command: touch .wkhtmltopdf

I've updated my script already and can confirm that this work. Thanks dhollenbeck

like image 16
Strabek Avatar answered Nov 13 '22 09:11

Strabek


I have insufficient reputation to comment everywhere, so my apologies that this is another answer, rather than just a comment on @dhollenbeck answer. Happy to delete this if that is updated.

gna.org has shut down thus 04_command will fail. A working list of downloads is on wkhtmltopdf.org.

The updated YAML scripts would therefore be.

Create yaml file .ebextensions/wkhtmltopdf.config:

commands:
  03_command:
    command: yum install --assumeyes zlib fontconfig freetype X11
  04_command:
    command: wget https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  05_command:
    command: tar -xJf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  06_command:
    command: cp wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
  07_command:
    command: cp wkhtmltox/bin/wkhtmltoimage /usr/local/bin/wkhtmltoimage

and if you only want to install wkhtmltopdf once to speed up subsequent deployments:

commands:
  03_command:
    command: yum install --assumeyes zlib fontconfig freetype X11
    test: test ! -f .wkhtmltopdf
  04_command:
    command: wget https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
    test: test ! -f .wkhtmltopdf
  05_command:
    command: tar -xJf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
    test: test ! -f .wkhtmltopdf
  06_command:
    command: cp wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
    test: test ! -f .wkhtmltopdf
  07_command:
    command: cp wkhtmltox/bin/wkhtmltoimage /usr/local/bin/wkhtmltoimage
    test: test ! -f .wkhtmltopdf
  08_command:
    command: touch .wkhtmltopdf
like image 5
Alistair H Avatar answered Nov 13 '22 09:11

Alistair H


An updated answer for wkhtmltopdf 0.12.4 installed on 64bit Amazon Linux 2016.09 v3.3.0.

Create yaml file .ebextensions/wkhtmltopdf.config

commands:
  03_command:
    command: yum install --assumeyes zlib fontconfig freetype X11
  04_command:
    command: wget http://download.gna.org/wkhtmltopdf/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  05_command:
    command: tar -xJf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  06_command:
    command: cp wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
  07_command:
    command: cp wkhtmltox/bin/wkhtmltoimage /usr/local/bin/wkhtmltoimage

If you only want to install wkhtmltopdf once to speed up subsequent deployments:

commands:
  03_command:
    command: yum install --assumeyes zlib fontconfig freetype X11
    test: test ! -f .wkhtmltopdf
  04_command:
    command: wget http://download.gna.org/wkhtmltopdf/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
    test: test ! -f .wkhtmltopdf
  05_command:
    command: tar -xJf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
    test: test ! -f .wkhtmltopdf
  06_command:
    command: cp wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
    test: test ! -f .wkhtmltopdf
  07_command:
    command: cp wkhtmltox/bin/wkhtmltoimage /usr/local/bin/wkhtmltoimage
    test: test ! -f .wkhtmltopdf
  08_command:
    command: touch .wkhtmltopdf

like image 4
dhollenbeck Avatar answered Nov 13 '22 07:11

dhollenbeck