How to install wkhtmltopdf on a linux based (shared hosting) web server
Asked Answered
F

12

68

I have tried in all ways to get wkhtmltopdf installed on our web server but unfortunately it is not getting installed. I cannot access user/bin folder as stated in a tutorial on installation.

On the server in public_html folder there is a sub folder _vti_bin, I copied the file wkhtmltopdf-i386 from wkhtmltopdf-0.9.1-static-i386, but I am not able to execute it.

How to install wkhtmltopdf on (shared hosting) web server and get it working?

Fournier answered 16/2, 2010 at 14:26 Comment(3)
What happens exactly (error message) when you execute it?Novitiate
If your binary fails silently, you might have the wrong one (i386 vs amd63). What command did you use to execute? How did it fail?Talyah
See How can I install the latest wkhtmltopdf on Ubuntu 16.04?Dentition
E
52

I've managed to successfully install wkhtmltopdf-amd64 on my shared hosting account without root access.

Here's what i did:

Downloaded the relevant static binary v0.10.0 from here: http://code.google.com/p/wkhtmltopdf/downloads/list

EDIT: The above has moved to here

via ssh on my shared host typed the following:

$ wget {relavant url to binary from link above}
$ tar -xvf {filename of above wget'd file}

you'll then have the binary on your host and will be able to run it regardless of if its in the /usr/bin/ folder or not. (or at least i was able to)

To test:

$ ./wkhtmltopdf-amd64 http://www.example.com example.pdf
  • Note remember that if you're in the folder in which the executable is, you should probably preface it with ./ just to be sure.

Worked for me anyway

Embrace answered 25/6, 2010 at 8:27 Comment(8)
This worked for me as well. I had to install LZMA util tukaani.org/lzma since tar version on my shared host did not support .lzma archive.Ceramist
For the people tuning in at this point, the tars are now bzipped (.bz2). You can unpack them with bunzip2 {filename}Talyah
@Christopher, I'm on a shared server, can't install. So I uploaded and uncompressed via c-panel, right to my current folder, and ran wkhtmltopdf-amd64 straight away with no paths etc. I get the error: "sh: wkhtmltopdf-amd64: command not found". Any ideas? On c-panel file manager, it says the file type is text/x-generic, if that means anything.Lemma
Never mind, I got it to work! :) Just needed to remember I'm on Linux and refer to it as "./wkhtmltopdf" instead of "wkhtmltopdf".Lemma
Added new link in answer, but to be honest, it is signposted that they're moved and we cant keep updating links, the answer still stands on its own.Embrace
Great solution but wkhtmltopdf is now a .deb file, and I'm not sure how to perform the same operation. I've been trying dpkg -x filename, but it doesn't seem to work. Any suggestions?Loup
@mtpultz: that is covered in the download FAQ -- see this post on the mailing list.Bales
Whether you will be allowed to do cyberciti.biz/faq/… on a hosted site is unclear - but otherwise you might have luck convince the hosting partner to do the lddand install parts for you, YMMV :$Campground
C
38

If you have sudo access...

Ubuntu 14.04 / 15.04 / 18.04:

sudo apt-get install wkhtmltopdf
# or
sudo apt install wkhtmltopdf

Others

Look at the other answers.

Chaunce answered 9/1, 2015 at 20:59 Comment(4)
sudo yum install wkhtmltopdf worked for me, for those of us on Others.Flagpole
sudo yum install wkhtmltopdf dosen't work. Getting 'No package wkhtmltopdf available.'Rhinehart
what's the equivalent for apt-get update but for yum?Chaunce
This doesn't really answer the OP's question, since they were on shared hosting - they very likely don't have sudo permissions and almost certainly don't have the ability to install new software via package managers (on most shared hosting options, anyway).Doting
S
27

If its ubuntu then go ahead with this, already tested.:--

first, installing dependencies

sudo aptitude install openssl build-essential xorg libssl-dev

for 64bits OS

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2 
tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf

for 32bits OS

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-i386.tar.bz2 
tar xvjf wkhtmltopdf-0.9.9-static-i386.tar.bz2
 mv wkhtmltopdf-i386 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf
Stonework answered 26/4, 2011 at 8:28 Comment(4)
Thanks for your tips. But we are hosting on shared servers and there we are not allowed to install anything.Fournier
@Yogi Yang 007 even on shared host u can ask for shell access. I tried on bluehost. I dont know its legal or not. :-)Stonework
Worked for me running an Ubuntu virtual machine server using Vagrant. Thanks, Mohit!Kaohsiung
Worked for me on Ubuntu 14.04, just be careful : the recent versions on the website are now in .tar.xz, use tar -xvf to unpack the files.Swirsky
D
6

Latest update for CentOS:

  • sudo yum install -y libpng libjpeg openssl icu libX11 libXext libXrender xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi
  • wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  • tar -xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  • sudo mv wkhtmltox/bin/* /usr/local/bin/
  • check installation success: wkhtmltopdf -V
  • rm -rf wkhtmltox
  • rm -f wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
Denise answered 15/11, 2021 at 16:51 Comment(0)
T
4

Debian 8 Jessie
This works sudo apt-get install wkhtmltopdf

Tomato answered 5/3, 2016 at 8:32 Comment(0)
N
3

Chances are that without full access to this server (due to being a hosted account) you are going to have problems. I would go so far as to say that I think it is a fruitless endeavor--they have to lock servers down in hosted environments for good reason.

Call your hosting company and make the request to them to install it, but don't expect a good response--they typically won't install very custom items for single users unless there is a really good reason (bug fixes for example).

Lastly, depending on how familiar you are with server administration and what you are paying for server hosting now consider something like http://www.slicehost.com. $20 a month will get you a low grade web server (256 ram) and you can install anything you want. However, if you are running multiple sites or have heavy load the cost will go up as you need larger servers.

GL!

Nay answered 16/2, 2010 at 16:8 Comment(0)
F
2

A few things have changed since the top answers were added. They used to work out for me, but not quite anymore, so I have been hacking around for a bit and came up with the following solution for Ubuntu 16.04. For Ubuntu 14.04, see the comment at the bottom of the answer. Apologies if this doesn't work for shared hosting, but it seems like this is the goto answer for wkhtmltopdf installation instructions in general.

# Install dependencies
apt-get install libfontconfig \
    zlib1g \
    libfreetype6 \
    libxrender1 \
    libxext6 \
    libx11-6

# TEMPORARY FIX! SEE: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/3001
apt-get install libssl1.0.0=1.0.2g-1ubuntu4.8
apt-get install libssl-dev=1.0.2g-1ubuntu4.8

# Download, extract and move binary in place
curl -L -o wkhtmltopdf.tar.xz https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar -xf wkhtmltopdf.tar.xz
mv wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf

Test it out:

wkhtmltopdf http://www.google.com google.pdf

You should now have a file named google.pdf in the current working directory.

This approach downloads the binary from the website, meaning that you can use the latest version instead of relying on package managers to be updated.

Note that as of today, my solution includes a temporary fix to this bug. I realize that the solution is really not great, but hopefully it can be removed soon. Be sure to check the status of the linked GitHub issue to see if the fix is still necessary when you read this answer!

For Ubuntu 14.04, you will need to downgrade to a different version of libssl. You can find the versions here. Anyways, be sure to consider the implications of downgrading libssl before doing so on any production server.

I hope this helps someone!

Fractional answered 7/8, 2017 at 11:48 Comment(0)
D
1

Place the wkhtmltopdf executable on the server and chmod it +x.

Create an executable shell script wrap.sh containing:

#!/bin/sh
export HOME="$PWD"
export LD_LIBRARY_PATH="$PWD/lib/"
exec $@ 2>/dev/null
#exec $@ 2>&1 # debug mode

Download needed shared objects for that architecture and place them an a folder named "lib":

  • lib/libfontconfig.so.1
  • lib/libfontconfig.so.1.3.0
  • lib/libfreetype.so.6
  • lib/libfreetype.so.6.3.18
  • lib/libX11.so.6 lib/libX11.so.6.2.0
  • lib/libXau.so.6 lib/libXau.so.6.0.0
  • lib/libxcb.so.1 lib/libxcb.so.1.0.0
  • lib/libxcb-xlib.so.0
  • lib/libxcb-xlib.so.0.0.0
  • lib/libXdmcp.so.6
  • lib/libXdmcp.so.6.0.0
  • lib/libXext.so.6 lib/libXext.so.6.4.0

(some of them are symlinks)

… and you're ready to go:

./wrap.sh ./wkhtmltopdf-amd64 --page-size A4 --disable-internal-links --disable-external-links "http://www.example.site/" out.pdf

If you experience font problems like squares for all the characters, define TrueType fonts explicitly:

@font-face {
  font-family:Trebuchet MS;
  font-style:normal;
  font-weight:normal;
  src:url("http://www.yourserver.tld/fonts/Trebuchet_MS.ttf");
  format(TrueType);
}
Dorsman answered 21/5, 2010 at 13:58 Comment(0)
I
1

List of stable versions wkhtmltopdf: http://wkhtmltopdf.org/downloads.html

Installing wkhtmltopdf on Debian 8.2 (jessie) x64:

sudo apt-get install xfonts-75dpi
sudo apt-get install xfonts-base
sudo wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-jessie-amd64.deb
sudo dpkg -i wkhtmltox-0.12.2.1_linux-jessie-amd64.deb
Interventionist answered 2/12, 2015 at 23:39 Comment(0)
S
1

Shared hosting no ssh or shell access?

Here is how i did it;

  1. Visit https://wkhtmltopdf.org/downloads.html and download the appropriate stable release for Linux. For my case I chose 32-bit which is wkhtmltox-0.12.4_linux-generic-i386.tar.xz
  2. Unzip to a folder on your local drive.
  3. Upload the folder to public_html (or whichever location fits your need) using an FTP program just like any other file(s)
  4. Change the binary paths in snappy.php file to point the appropriate files in the folder you just uploaded. Bingo! there you have it. You should be able to generate PDF files.
Subclavian answered 25/7, 2017 at 21:34 Comment(3)
hi, this not work. get error : libXrender.so.1: cannot open shared object file: No such file or directory" }. how to fix it ?Bak
@Chielarck Check whether you've downloaded for right architecture e.g 32bit. Also make you've included snappy dependencies in your project.Subclavian
can you give me direct link ? I've tried downloading. but nothing worksBak
S
0

After trying, below command work for me

cd ~
yum install -y xorg-x11-fonts-75dpi xorg-x11-fonts-Type1 openssl git-core fontconfig
wget https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
mv wkhtmltox/bin/wkhtmlto* /usr/bin
Selfesteem answered 1/3, 2018 at 10:31 Comment(1)
thanks need to add sudo before mv after installing or got a permission error, worked for meMenjivar
H
-1

Version 12.5 of wkhtmltopdf only lists DEB files on their download page now. Being a mac user and not knowing much linux or what DEB files were I couldn't use the solutions posted.

This page helped me get past the knew twist of downloading a DEB file: http://www.g-loaded.eu/2008/01/28/how-to-extract-rpm-or-deb-packages/

Basically what I did was:

  1. Downloaded from https://wkhtmltopdf.org/downloads.html
  2. Unzipped the DEB file.
  3. Unzipped data.tar.xz
  4. Uploaded the binary in the unzipped 'usr' folder from step 3 (usr/local/bin/wkhtmltopdf)

Then I found out that the 'exec' function was disabled on my host. So make sure you can specifically run 'exec' if you're using PHP to run this. "Can I run the wkhtmltopdf binary" isn't specific enough. My fault.

Hortative answered 1/5, 2019 at 0:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.