Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wkhtmltopdf support? #567

Closed
khoerodin opened this issue Jan 25, 2017 · 21 comments
Closed

wkhtmltopdf support? #567

khoerodin opened this issue Jan 25, 2017 · 21 comments

Comments

@khoerodin
Copy link

Hi..
Iam trying to install Laravel Snappy, i am also install wkhtmltopdf and libXrender1 on workspace container, and when generating PDF with wkhtmltopdf, showing an error:

The exit status code '127' says something went wrong:
stderr: "/var/www/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64: error while loading shared libraries: libXrender.so.1: cannot open shared object file: No such file or directory

Can anybody help me please?
error

@Lednerb
Copy link
Contributor

Lednerb commented Jan 29, 2017

Hello @khoerodin

in an older version of laradock I've used this changes:

docker-compose.yml under the workspace section:

workspace:
        build:
            context: ./workspace
            args:
                - INSTALL_XDEBUG=false
                - ...
                - INSTALL_WKHTMLTOPDF=true

workspace/Dockerfile after the last install option:

#####################################
# wkhtmltopdf:
#####################################

ARG INSTALL_WKHTMLTOPDF=true
RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
    # Install all dependencies
    apt-get install -y \
    libxrender1 \
    libfontconfig1 \
    libx11-dev \
    libjpeg62 \
    libxtst6 \
    wget \
    && wget https://github.com/h4cc/wkhtmltopdf-amd64/blob/master/bin/wkhtmltopdf-amd64?raw=true -O /usr/local/bin/wkhtmltopdf \
    && chmod +x /usr/local/bin/wkhtmltopdf \
;fi


#####################################
# supervisor - process manager
#####################################

RUN apt-get update && apt-get install -y supervisor --fix-missing
COPY laravel-worker.conf /etc/supervisor/conf.d/laravel-worker.conf

TL;DR

You have to install more than only libXrender1 package.
Maybe the RUN command above helps you.

EDIT:
Have a look at this: #312

@khoerodin
Copy link
Author

stay not working for me ..

@rogerroelofs
Copy link

rogerroelofs commented Jun 20, 2017

I added the following to my php-fpm Dockerfile (I'm using -56 but would expect others to work also)

RUN \
  apt-get update && \
  apt-get install -y fonts-droid fontconfig libfontconfig1 libfreetype6 libpng12-0 libssl1.0.0 libx11-6 libxext6 libxrender1 xfonts-75dpi xfonts-base wget xz-utils && \
  cd /tmp && \
  wget -nv https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz -O wkhtmltox.tar.xz && \
  tar -xaf wkhtmltox.tar.xz && \
  rm -f wkhtmltox.tar.xz && \
  mv wkhtmltox/bin/wkhtmlto* /usr/local/bin/ && \
  apt-get -y install libtidy-dev && \
  docker-php-ext-install tidy && \
  apt-get clean && rm -rf /var/lib/apt/lists/*

@guicara
Copy link

guicara commented May 17, 2018

It is really important to install the libssl1.0-dev package, otherwise you will have the QSslSocket: cannot resolve (...) errors with wkhtmltopdf.
See wkhtmltopdf/wkhtmltopdf#3001.

Also, with the last version of Laradock, I had to remove the libx11-dev package in order to build nginx without any errors.

@ndberg
Copy link

ndberg commented Nov 22, 2018

I couldn't get it to work with the static binaries from @h4cc from github.

After a lot of problems and research I fixed it with adding this to php-fpm/dockerfile, which will build it from source, one time the debian package for the php-fpm container and one time the ubuntu package for the workspace container.

#####################################
# wkhtmltopdf:
#####################################

 ARG INSTALL_WKHTMLTOPDF=true
 RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
     apt-get update && apt-get install -y libxrender1 libfontconfig1 libx11-dev libjpeg62 libxtst6 wget \
     && mkdir wkhtmltopdf_download \
     && cd wkhtmltopdf_download \
     && wget https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb \
     && apt install ./wkhtmltox_0.12.5-1.stretch_amd64.deb -y \
     && cd .. \
     && rm -rf wkhtmltopdf_download \
 ;fi

This to workspace/dockerfile

#####################################
# wkhtmltopdf:
#####################################
 USER root

 ARG INSTALL_WKHTMLTOPDF=true
 RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
     # Install all dependencies
     apt-get update && apt-get install -y libxrender1 libfontconfig1 libx11-dev libjpeg62 libxtst6 wget \
     && mkdir wkhtmltopdf_download \
     && cd wkhtmltopdf_download \
     && wget https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb \
     && apt install ./wkhtmltox_0.12.5-1.bionic_amd64.deb -y \
     && cd .. \
     && rm -rf wkhtmltopdf_download \
 ;fi

And the variables to docker-compose.yml

workspace:
      build:
        context: ./workspace
        args:
          - .. a lot of others..
          - INSTALL_WKHTMLTOPDF=true

php-fpm:
      build:
        context: ./php-fpm
        args:
          - .. a lot of others ..
          - INSTALL_WKHTMLTOPDF=true

Hope it helps someone..

@mrbase
Copy link

mrbase commented Nov 23, 2018

@ndberg
If I try this, the workspace version is build, but the php-fpm version fails.

@ndberg
Copy link

ndberg commented Nov 26, 2018

@mrbase I updated the Code, i had troubles myself as the command:
cd /var/www
raised an error. Otherwise you have to check with what an error it fails.

@mrbase
Copy link

mrbase commented Nov 26, 2018

Actually ended up using the binary from https://github.com/h4cc/wkhtmltopdf-amd64/

The errors I got was rather confusing

@guicara
Copy link

guicara commented Jan 30, 2019

Hello,

Today I have installed Laradock on a new computer, and I faced once again the same issues with wkhtmltopdf on Laradock.

I tried the solution of @ndberg : the workspace and php-fpm build, but I have this error when I run wkhtmltopdf:

/usr/local/bin/wkhtmltopdf: /lib/x86_64-linux-gnu/libm.so.6: version GLIBC_2.27 not found (required by /usr/local/bin/wkhtmltopdf)

So I ended up using the binary from h4cc (thanks @mrbase).
But I had this error message:

The exit status code '1' says something went wrong: QSslSocket: cannot resolve ...

As I said in my message last year, you must install the libssl1.0-dev package in the php-fpm container and the libssl1.0.0 package in the workspace container.

Step-by-step instructions

I have tested it on a fresh installation of Laradock (last version) with a Laravel project using Laravel Snappy.

  1. Use Composer to install the h4cc/wkhtmltopdf-amd64 package that provided the static compiled binaries from the wkhtmltopdf project.

  2. If you use Laravel Snappy, you must change the path of the binary.

For example:

'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),


The next steps are only mandatory if you use wkhtmltopdf <= 0.12.4. The last version of wkhtmltopdf (0.12.5) should fix the problem with QSslSocket (see here). Unfortunately, at the time of writing this post, the h4cc/wkhtmltopdf-amd64 package still use the 0.12.4 version of wkhtmltopdf, and it will probably never be updated.

  1. Add the INSTALL_WKHTMLTOPDF constants in the docker-compose.yml file as described by @ndberg

File to edit: /laradock/docker-compose.yml

workspace:
      build:
        context: ./workspace
        args:
          - .. a lot of others..
          - INSTALL_WKHTMLTOPDF=true

php-fpm:
      build:
        context: ./php-fpm
        args:
          - .. a lot of others ..
          - INSTALL_WKHTMLTOPDF=true
  1. Install libssl1.0-dev in the php-fpm Laradock container:

File to edit: /laradock/php-fpm/Dockerfile

#####################################
# wkhtmltopdf:
#####################################

ARG INSTALL_WKHTMLTOPDF=true
RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
	apt-get update && apt-get install -y libssl1.0-dev \
;fi

Rebuild the container: docker-compose build php-fpm

  1. Install libssl1.0.0 in the workspace Laradock container:

File to edit: /laradock/workspace/Dockerfile

#####################################
# wkhtmltopdf:
#####################################

USER root

ARG INSTALL_WKHTMLTOPDF=true
RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
	# Install all dependencies
	apt-get update && apt-get install -y libssl1.0.0 \
;fi

Rebuild the container: docker-compose build workspace

Hope it helps!

@Lednerb
Copy link
Contributor

Lednerb commented Jan 31, 2019

@guicara Maybe we should extend the script sections

ARG INSTALL_WKHTMLTOPDF=true
RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \

with commands to download and install the latest versions from https://wkhtmltopdf.org/downloads.html with all needed dependencies?

Than the outdated and abandoned h4cc/wkhtmltopdf package would not be needed, and a secure and fixed version of libssl can be used instead?
More information about the vulnerability:

@pixelplant
Copy link

Anyone has an update on this request? It would be nice to have it already integrated inside laradock with the proper wkhtmltopdf version

@johdougss
Copy link
Contributor

workspace:
      build:
        context: ./workspace
        args:
          - .. a lot of others..
          - INSTALL_WKHTMLTOPDF=true

php-fpm:
      build:
        context: ./php-fpm
        args:
          - .. a lot of others ..
          - INSTALL_WKHTMLTOPDF=true

workspace\Dockerfile

###########################################################################
# WKHTMLTOPDF
###########################################################################
ARG INSTALL_WKHTMLTOPDF=false

RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
 apt-get -y install fontconfig libxext6 libxrender1 xfonts-utils \
   libfontenc1 libxfont1 x11-common xfonts-75dpi xfonts-base \
 && wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.xenial_amd64.deb \
 && dpkg -i --force-depends wkhtmltox_0.12.5-1.xenial_amd64.deb \
;fi

php-fpm\Dockerfile

###########################################################################
# WKHTMLTOPDF
###########################################################################
ARG INSTALL_WKHTMLTOPDF=false

RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
 apt-get update && apt-get -y install fontconfig libxext6 libxrender1 xfonts-utils \
     libfontenc1 libxfont1 x11-common xfonts-75dpi xfonts-base \
 && curl -L -o /tmp/wkhtmltopdf.deb https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb \
 && dpkg -i --force-depends /tmp/wkhtmltopdf.deb \
;fi

@glebgoloborodko
Copy link

glebgoloborodko commented Dec 2, 2019

@johnathansantos Perfect. This help me a lot.

And also this is working in php-worker ONLY (!!!) if php-worker is inside workspace (#2330).

Don't know why but wkhtmltopdf not working in php-worker as separate container

@mrbase
Copy link

mrbase commented Dec 2, 2019

@glebgoloborodko You need to add it to the php-worker image as well.

@glebgoloborodko
Copy link

@glebgoloborodko You need to add it to the php-worker image as well.

Sorry. Yes I fixed it already) thanks

@andrepaes
Copy link

@glebgoloborodko You need to add it to the php-worker image as well.

Sorry. Yes I fixed it already) thanks

Bro, how do you installed these packages on php-worker since it use alpine linux?

@andrepaes
Copy link

@glebgoloborodko You need to add it to the php-worker image as well.

Sorry. Yes I fixed it already) thanks

I guess you had the same issue than me =/. I can generate the pdf perfectly when it's called at controller. When i need to generate it on jobs/queues, it's throw an error 127 and it seems the package isn't installed. I installed using composer, so my path on snappy.php is the base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64').
I try to install it on php-fpm, workspace and php-worker but the problem still occuring.
Can you help me, please?
thanks in advance

@glebgoloborodko
Copy link

glebgoloborodko commented Dec 5, 2019

@andrepaes as I said wkhtmltopdf is working ONLY if php-worker is inside workspace container (#2330).
I also installed wkhtmltopdf 0.12.5 (now I not use 'vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'). @johnathansantos had a little mistake in php-fpm file.

How I did this:

  1. Upgrade to latest version of laradock. PHP-worker in workspace was added only in 28 Oct 2019. You can see this in doc - https://laradock.io/documentation/#install-supervisor

  2. update "docker-compose.yml" file


workspace:
      build:
        context: ./workspace
        args:
          - INSTALL_WKHTMLTOPDF=${WORKSPACE_INSTALL_WKHTMLTOPDF}


php-fpm:
      build:
        context: ./php-fpm
        args:
          - INSTALL_WKHTMLTOPDF=${PHP_FPM_INSTALL_WKHTMLTOPDF}

  1. update ".env"

WORKSPACE_INSTALL_WKHTMLTOPDF=true

PHP_FPM_INSTALL_WKHTMLTOPDF=true

  1. update "env-example"

WORKSPACE_INSTALL_WKHTMLTOPDF=true
PHP_FPM_INSTALL_WKHTMLTOPDF=true

WORKSPACE_INSTALL_SUPERVISOR=true
WORKSPACE_INSTALL_PYTHON=true

  1. update "workspace\Dockerfile"

###########################################################################
# WKHTMLTOPDF
###########################################################################
ARG INSTALL_WKHTMLTOPDF=false

RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
 apt-get -y install fontconfig libxext6 libxrender1 xfonts-utils wget \
   libfontenc1 x11-common xfonts-75dpi xfonts-base \
 && wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.xenial_amd64.deb \
 && dpkg -i --force-depends wkhtmltox_0.12.5-1.xenial_amd64.deb \
;fi

  1. update "php-fpm\Dockerfile"

###########################################################################
# WKHTMLTOPDF
###########################################################################
ARG INSTALL_WKHTMLTOPDF=false

RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
 apt-get update && apt-get -y install fontconfig libxext6 libxrender1 xfonts-utils wget \
     libfontenc1 x11-common xfonts-75dpi xfonts-base \
 && curl -L -o /tmp/wkhtmltopdf.deb https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb \
 && dpkg -i --force-depends /tmp/wkhtmltopdf.deb \
;fi

  1. add new conf in "php-worker\supervisor.d". For example "php-worker\supervisor.d\test.conf". This example using redis as queues

[program:test]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/test/artisan queue:work redis --sleep=1 --tries=1 --daemon
autostart=true
autorestart=true
numprocs=1
user=laradock
redirect_stderr=true
stdout_logfile=/var/www/test/storage/logs/queue-jobs.log

  1. build workspace.

docker-compose stop workspace

docker-compose up --build -d workspace

Now when you will enter workspace:

docker-compose exec --user=laradock workspace bash

You must see your "test.conf" file from "php-worker\supervisor.d" in
"/etc/supervisord.d/test.conf"

  1. Run redis and what you need for your work

docker-compose up -d nginx php-fpm redis

  1. In Laravel project in "config/snappy.php" I have path to pdf binary like this

'pdf'   => array(
        'enabled' => true,
        'binary' => '/usr/local/bin/wkhtmltopdf'

  1. Setup .env for redis

QUEUE_DRIVER=redis

REDIS_HOST=redis // (it's config in config\database.php -> redis.default.host)

  1. Run supervisord

docker-compose exec --user=laradock workspace bash

/usr/local/bin/supervisord

  1. Now it's working! Also you can restart supervisor with

/usr/local/bin/supervisorctl restart all

@stale
Copy link

stale bot commented Mar 4, 2020

Hi 👋 this issue has been automatically marked as stale 📌 because it has not had recent activity 😴. It will be closed if no further activity occurs. Thank you for your contributions ❤️.

@stale stale bot added the Stale label Mar 4, 2020
@stale
Copy link

stale bot commented Mar 25, 2020

Hi again 👋 we would like to inform you that this issue has been automatically closed 🔒 because it had not recent activity during the stale period. We really really appreciate your contributions, and looking forward for more in the future 🎈.

@stale stale bot closed this as completed Mar 25, 2020
@johdougss
Copy link
Contributor

update host

https://downloads.wkhtmltopdf.org to https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download

wkhtmltopdf/wkhtmltopdf@ba575ea

php-fpm\Dockerfile

###########################################################################
# WKHTMLTOPDF
###########################################################################
ARG INSTALL_WKHTMLTOPDF=false

RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
 apt-get update && apt-get -y install fontconfig libxext6 libxrender1 xfonts-utils \
     libfontenc1 libxfont1 x11-common xfonts-75dpi xfonts-base \
 && curl -L -o /tmp/wkhtmltopdf.deb https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb \
 && dpkg -i --force-depends /tmp/wkhtmltopdf.deb \
;fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests