在AWS ElasticBeanstalk上安装WKHTMLTOX(WKHTMLTOPDF + WKHTMLTOIMAGE)

13
我需要在我的 AWS EB 应用程序中安装 WKHTMLTOX。 我找到了这篇教程,它可以运行但是只支持旧版本。
请问是否有人将最新版(0.12.3)安装在 AWS EB 上?因为文件夹结构有些不同。
7个回答

16
尝试了不同的教程,包括这个后,我终于使它工作了 - 我更新了porteaux的答案。 我在我的EB *.config文件中的commands部分添加了以下代码:
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. 以上教程适用于Ubuntu,而AWS EB运行Amazon Linux,因此使用yum而不是apt-get。
  2. 我必须在tar命令中使用J开关来处理*.xz文件。
  3. 最后,我不得不将wkhtmltopdf和wkhtmltoimage文件都复制到bin文件夹中。

完成了!希望这能帮助其他人。

更新:根据dhollenbeck的建议

 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

我已经更新了我的脚本,可以确认这个有效。谢谢dhollenbeck。


缩短为一个命令:curl -L https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz | tar -xvJf - wkhtmltox/bin/wkhtmltopdf -C /usr/local^C - cmc

6

其他答案目前似乎都没有完全正常运行(一些原因是链接不再有效,另一些原因是新的依赖性问题)。我没有足够的声望来评论Lucas D'Avila的答案,所以这是一个对我而言在Amazon-Linux/2.9.7上正常工作的解决方案:

创建一个名为.ebextensions/wkhtmltopdf.config的.ebextensions文件。

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

如果已经安装了该软件包,则会出现错误。 这是一个不错的解决方案,但缺乏细节。 - Francisco J Sucre G
2
好的观点。我已经编辑了答案,恢复到一个早期版本,我已经使用了很长时间而没有问题。 - Elric Pedder
它给了我以下错误 - 有什么解决方案吗?[ERROR] 更新进程 [web cfn-hup nginx healthd] 的 pid 符号链接失败,出现错误:读取 pid 源文件 /var/pids/web.pid 失败,出现错误:打开 /var/pids/web.pid:没有那个文件或目录 2021/09/16 15:06:59.391295 [ERROR] 在执行命令 [app-deploy] - [Track pids in healthd] 期间发生错误。停止运行该命令。错误:更新进程 [web cfn-hup nginx healthd] 的 pid 符号链接失败,出现错误:读取 pid 源文件 /var/pids/web.pid 失败,出现错误:打开 /var/pids/web.pid:没有那个文件或目录。 - Hardik Vinzava

5

由于我的声望不足以在所有地方进行评论,所以我很抱歉这又是一个答案,而不仅仅是对@dhollenbeck答案的评论。如果有更新,我很乐意删除这个回答。

gna.org已经关闭,因此04_command将无法运行。可以在wkhtmltopdf.org上找到可工作的下载列表

因此,更新后的YAML脚本应该是这样的。

创建yaml文件.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

如果您只想安装一次wkhtmltopdf以加速后续部署:

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

4

针对安装在64位Amazon Linux 2016.09 v3.3.0上的wkhtmltopdf 0.12.4的更新答案。

创建yaml文件 .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

如果您只想安装一次wkhtmltopdf以加速后续部署:

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


1

补充 Elric Pedder 的回答。

如果已经安装了 wkhtmltopdf,则会出现错误,因为 yum 会给出“错误:没有要做的事情”并以 -1 状态退出。这将在重新部署弹性豆腐丝时发生。

为了成功安装 wkhtmltopdf,我检查是否已经安装。

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

0

您还可以通过创建一个名为.ebextensions/packages.config的文件并添加以下内容来安装wkhtmltopdf:

packages:
  rpm:
    # find more versions on https://wkhtmltopdf.org/downloads.html
    wkhtmltopdf: https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.centos7.x86_64.rpm

-1
wget https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.centos6.x86_64.rpm

sudo yum install wkhtmltox-0.12.5-1.centos6.x86_64.rpm

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接