barryvdh/laravel-snappy

The exit status code '127' says something went wrong: stderr: "sh: 1: /usr/local/bin/wkhtmltopdf: not found

Opened this issue ยท 32 comments

I am using laravel-snappy in Laravel 5.0 on Ubuntu 14.04. I installed laravel-snappy and wkhtmltopdf via composer. But when I tried to use it in one of the method, this is the error i am getting:

RuntimeException in AbstractGenerator.php line 336:
The exit status code '127' says something went wrong:
stderr: "sh: 1: /usr/local/bin/wkhtmltopdf: not found
"
stdout: ""
command: /usr/local/bin/wkhtmltopdf --lowquality --orientation 'portrait' --page-size 'a4' '/tmp/knp_snappy55fbeb8b97a097.69359150.html' '/tmp/knp_snappy55fbeb8b97a8d0.78089447.pdf'.

I need to change the path? How can I change the path? I can't find any section of code referring to laravel snappy or wkhtmltopdf. I need help. Thank you.

Did you manage to fix this @aacsssh? I'm having the same problem.

Getting the same issue

@bradbird1990 No, I used laravel-dompdf instead. Did you fixed this?

@awkwardusername Thank you for the link. I already have those packages installed. But no help.

@aacsssh Check whether you installed 'h4cc/wkhtmltopdf' for 32 bit and 64 bit. And make sure you have same bit based system.

@aacsssh if you have wkhtmltopdf installed, it s probably installed on /usr/bin/wkhtmltopdf, so you need to create a symbolic link to it from where snappy is looking for it in /usr/local/bin/wkhtmltopdf:
try this:

sudo ln -s /usr/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf

edit: Or you might also edit the binary property in the snappy.php file in your vendor directory:

'pdf' => array(
        'enabled' => true,
        'binary'  => '/usr/local/bin/wkhtmltopdf',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    )

But this will certainly only work localy.

I just installed wkhtmltopdf on a centos 6 - 64bin machine. It works fine in my Laravel application. If anybody is still having problem/issues you can also refer to my notes in

https://thajegan76.wordpress.com/category/laravel/

I solved this by executing dependencies next command like in the post @awkwardusername suggested

Debian or Ubuntu:

sudo apt-get install libxrender1

If you are using the i386 binary and you get the 127 error, try switching to the amd64 binary, even if you have an intel processor. That worked for me.

I had this issue and it had to do with referencing the incorrect path. I had to change mine from /usr/local/bin/wkhtmltopdf to /usr/bin/wkhtmltopdf a simple way to test if to copy + paste /usr/<your_path_here>/bin/wkhtmltopdf into the terminal, and if you get the man page for wkhtmltopdf you're good to go. hope this helps

lvsof commented

Following the installation instructions, I ended up with incorrect binary paths in the config/snappy.php file resulting in the same error. It was pointing to the bin directory even though I installed using composer and they were installed in the vendor directory for my project.

I was also doing this locally on a Mac and learned that the suggested wkhtmltopdf binaries didn't work. Here's the pdf one for osx. I assume there's one for images as well.

Hope this helps someone :)

I used these commands to get both pdf and image working fine on my Laravel.forge install.
You may need sudo for the wget and chmod steps
#####################################

wkhtmltopdf:

#####################################

#### 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 \

#####################################

wkhtmltoimage:

#####################################

Install all dependencies

apt-get install -y \
libxrender1 \
libfontconfig1 \
libx11-dev \
libjpeg62 \
libxtst6 \
wget \
&& wget https://github.com/h4cc/wkhtmltoimage-amd64/blob/master/bin/wkhtmltoimage-amd64?raw=true -O /usr/local/bin/wkhtmltoimage \
&& chmod +x /usr/local/bin/wkhtmltoimage \

I ran into this issue after updating packages with composer in a centos docker image. As previously mentioned, you need to install dependencies. The mix that worked for me was the one found in wkhtmltopdf's Centos documentation:

yum install fontconfig libXrender libXext xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi freetype libpng zlib libjpeg-turbo

I had the same issue on ubuntu but after the following steps, I have no issue. Before this, I checked if the libxrender1 package is already installed or not and then I proceed further.

  1. After installing laravel snappy I copied the required file and put into /usr/local/bin folder like this

cp vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64 /usr/local/bin/
cp vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 /usr/local/bin/

and make them executable file by this

sudo chmod +x /usr/local/bin/wkhtmltoimage-amd64
sudo chmod +x /usr/local/bin/wkhtmltopdf-amd64

  1. Now update the config file with following content
	return array(


    'pdf' => array(
        'enabled' => true,
        // 'binary'  => '/usr/local/bin/wkhtmltopdf', First I use this.
        'binary'  => '/usr/local/bin/wkhtmltopdf-amd64',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),
    'image' => array(
        'enabled' => true,
        // 'binary'  => '/usr/local/bin/wkhtmltoimage', First I use this.
        'binary'  => '/usr/local/bin/wkhtmltoimage-amd64',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),

);

Hope it will work

Primero busca si tienes la libreria

apt-cache search libXext
libxext-dev - X11 miscellaneous extensions library (development headers)
libxext-doc - X11 miscellaneous extensions library (documentation)
libxext6 - X11 miscellaneous extension library
libxext6-dbg - X11 miscellaneous extensions library (debug package)

Luego de encontrar el nombre de la libreria instalarla

apt-get install libxext6

I use Ubuntu 18.04 and by following the steps mentioned in the following doc solved my issue. Instructions also available on other version and OS.

https://gist.github.com/srmds/2507aa3bcdb464085413c650fe42e31d

I use Ubuntu 16.04 and that's fixed the problem:

sudo apt-get install libxrender1

Update on December 18 one week before Christmas :
I use Laravel Forge recipe, there is a recipe called Install WkhtmlToPDF, run it, then in config/snappy.php in binary section I just write this :

'binary' => 'wkhtmltopdf',

and similar for the image, of course
and it works like a charm.
Very thank you for the guys who build these whole systems.

sudo ln -s /usr/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf

This line is the real deal! Thank you.

FYI running on MAC OS High Sierra.

@aacsssh if you have wkhtmltopdf installed, it s probably installed on /usr/bin/wkhtmltopdf, so you need to create a symbolic link to it from where snappy is looking for it in /usr/local/bin/wkhtmltopdf:
try this:

sudo ln -s /usr/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf

edit: Or you might also edit the binary property in the snappy.php file in your vendor directory:

'pdf' => array(
        'enabled' => true,
        'binary'  => '/usr/local/bin/wkhtmltopdf',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    )

But this will certainly only work localy.

If anyone else ran into this because your dev binaries might be in a different location from your production/staging environment's I do the following:

config/snappy.php

return [

    'pdf' => [
        'enabled' => true,
        'binary' => env('WKHTMLTOPDF_BINARY_PATH', '/usr/local/bin/wkhtmltopdf'),
        'timeout' => false,
        'options' => [],
        'env' => [],
    ],

    'image' => [
        'enabled' => true,
        'binary' => env('WKHTMLTOIMAGE_BINARY_PATH', '/usr/local/bin/wkhtmltoimage'),
        'timeout' => false,
        'options' => [],
        'env' => [],
    ],

];

.env (Windows)

WKHTMLTOPDF_BINARY_PATH="C:\\wkhtmltopdf\\bin\\wkhtmltopdf.exe"
WKHTMLTOIMAGE_BINARY_PATH="C:\\wkhtmltopdf\\bin\\wkhtmltoimage.exe"

My staging and production environments are both Linux servers so they just use the default location if the env value isn't set.

This is how I fixed this issue:
The file could be in the right directory /usr/local/bin but with a wrong name.
So check the directory files, if you're in Ubuntu or vagrant run

  1. cd /usr/local/bin
  2. ls
  3. check the files inside the directory, the file name could be wkhtmltopdf-amd64
  4. sudo mv wkhtmltopdf-amd64 wkhtmltopdf
  5. Done!

If you are using docker, install wkhtmltopdf on the container

I face this problem. Its live shared hosting service. Somebody, please help.
image

I face this problem. Its live shared hosting service. Somebody, please help.
image

Remove all about wkhtmltopdf and try again following this: #68 (comment) or #68 (comment)

I used these commands to get both pdf and image working fine on my Laravel.forge install.
You may need sudo for the wget and chmod steps
#####################################

wkhtmltopdf:

#####################################

#### 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 \

#####################################

wkhtmltoimage:

#####################################

Install all dependencies

apt-get install -y \
libxrender1 \
libfontconfig1 \
libx11-dev \
libjpeg62 \
libxtst6 \
wget \
&& wget https://github.com/h4cc/wkhtmltoimage-amd64/blob/master/bin/wkhtmltoimage-amd64?raw=true -O /usr/local/bin/wkhtmltoimage \
&& chmod +x /usr/local/bin/wkhtmltoimage \

Thanks! That worked on:

Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic

PHP 7.2.24-0ubuntu0.18.04.3 (cli) (built: Feb 11 2020 15:55:52) ( NTS )

Laravel Framework 5.8.37

After copy both folder then give 777 permission.

This is a major thing you should do.

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/KnpLabs/snappy instead. When having doubts, please try to reproduce the issue with just snappy.
If you believe this is an actual issue with the latest version of laravel-snappy, please reply to this issue so we can investigate further.
Thank you for your contribution! Apologies for any delayed response on our side.

This works in 2022! Thank's a ton โค๏ธ

I used these commands to get both pdf and image working fine on my Laravel.forge install. You may need sudo for the wget and chmod steps #####################################

wkhtmltopdf:

#####################################

#### 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 \

#####################################

wkhtmltoimage:

#####################################

Install all dependencies

apt-get install -y \
libxrender1 \
libfontconfig1 \
libx11-dev \
libjpeg62 \
libxtst6 \
wget \
&& wget https://github.com/h4cc/wkhtmltoimage-amd64/blob/master/bin/wkhtmltoimage-amd64?raw=true -O /usr/local/bin/wkhtmltoimage \
&& chmod +x /usr/local/bin/wkhtmltoimage \

My fix:

Installed wkhtmltopdf on my server
sudo apt update
sudo apt install wkhtmltopdf

After successful installation, I find the wkhtmltopdf and create a symlink
find / -name wkhtmltopdf
ln -s /usr/bin/wkhtmltopdf /usr/local/bin/whtmltopdf-amd64

For me, this is the fix for my encountered errors such as 'ssl resources not loading, error 127, libssl error, and many more'
I think it is case to case basis depends on the environment and versions of platforms. Thanks.

My Platform Details:

  • Ubuntu 22.04
  • Laravel Forge on DigitalOcean
  • Laravel 9
  • PHP 8.1

wget \

worked 2023 even with composer vendor