Lucas Vieira
Lucas Vieira

Reputation: 96

How to fix 'Error while loading shared libraries: libpng12.so.0' (on dokku)

I'm having some trouble while trying to generate an pdf through the pdf_from_url method on production. The error is the following:

Error: PDF could not be generated!
 Command Error: /app/vendor/bundle/ruby/2.5.0/gems/wkhtmltopdf-binary-edge-0.12.5.0/libexec/wkhtmltopdf-linux-amd64: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory

The line bellow throws the error above:

   pdf = WickedPdf.new.pdf_from_url("https://google.com", {:temp_path => Rails.root.join('public')})

The error only occurs on production. Everything works normaly on development.

Running wkhtmltopdf https://google.com test.pdf via command line on the server works normally.

One thing to notice is that my application server runs on a dokku container, which i'm inexperienced in. So, probably the error occurs due to the way of how dokku's file architeture works.

What i have already tried:

  1. Changed wkhtmltopdf's gem from wkhtmltopdf-binary to wkhtmltopdf-binary-edge
  2. Installed libpng12 manualy on the server (not on dokku container)

What i'm using currently:

wicked_pdf gem version: 1.1.0

whtmltopdf [provider gem]: wkhtmltopdf-binary-edge ~> 0.12.5

platform/distribution and version: Dokku container running on Ubuntu 18.04

Upvotes: 2

Views: 4817

Answers (3)

Chalie
Chalie

Reputation: 51

I managed to solve such by installing libpng12-0 from a deb file.

wget -q -O libpng12.deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb && sudo dpkg -i libpng12.deb && rm libpng12.deb

Upvotes: 1

Lucas Vieira
Lucas Vieira

Reputation: 96

I managed to solve that problem by using dokku-apt plugin to install the libpng12.

First, install the dokku-apt plugin on your dokku container:

sudo dokku plugin:install https://github.com/F4-Group/dokku-apt

Then, create a file named apt-packages on your root project directory and insert the name of the lib like:

libpng12-0

After that, create another file named apt-repositories on your root project directory and insert the following line to update your repositories: (remember to leave an empty line on the end of the file)

deb http://security.ubuntu.com/ubuntu xenial-security main

At last, commit and deploy those files to your dokku container and it should work.

Upvotes: 1

Yurui Zhang
Yurui Zhang

Reputation: 2232

for ubuntu 18.04 you should try

https://github.com/rposborne/wkhtmltopdf-heroku

(even though it says heroku ,it should work for most ubuntu 18.04 environments)

wkthmltopdf-binary-edge is not meant to be used outside of dev environments.

if the heroku gem doesn't work for you you could try to downgrade wkhtmltopdf-binary-edge to 0.12.4 or 0.12.3. I believe 0.12.5 binary has some issues with 18.04.

Upvotes: 0

Related Questions