php-vips-ext icon indicating copy to clipboard operation
php-vips-ext copied to clipboard

php-vips has not been configured for PDF support

Open fsnightmckngbrd opened this issue 6 years ago • 19 comments

I've encountered an error while using php-vips and I'm encountering this error vips_image_get: field "n-pages".

I've followed all the instructions on the installation of this extension except for the composer. I installed the library using the command found on the composer composer require jcupitt/vips instead of adding "jcupitt/vips" : "1.0.0" on my composer.json. I'm not sure if this is the problem. Thanks!

fsnightmckngbrd avatar Oct 24 '19 21:10 fsnightmckngbrd

Hello @fsnightmckngbrd,

My guess is your libvips build does not have PDF support, or you have a very old libvips. Is this a Debian-derived linux? Install libvips-tools and try this in a terminal window:

vipsheader -a some-test-pdf-file.pdf

And paste what you see here.

I see:

$ vipsheader -a nipguide.pdf
nipguide.pdf: 595x842 uchar, 4 bands, srgb, pdfload
width: 595
height: 842
bands: 4
format: uchar
coding: none
interpretation: srgb
xoffset: 0
yoffset: 0
xres: 2.83465
yres: 2.83465
filename: nipguide.pdf
vips-loader: pdfload
pdf-n_pages: 58
n-pages: 58
pdf-creator: TeX
pdf-producer: pdfTeX-1.40.16

jcupitt avatar Oct 25 '19 04:10 jcupitt

Hi sir, I guessed that libvips-tools was already installed so I tried the command you said and here is what I got.

document_4.2_clean.pdf: 792x612 ushort, 4 bands, rgb16, magickload
width: 792
height: 612
bands: 4
format: 2 - ushort
coding: 0 - none
interpretation: 25 - rgb16
xoffset: 0
yoffset: 0
xres: 1.000000
yres: 1.000000
filename: "document_4.2_clean.pdf"
vips-loader: magickload
magick-date:create: 2019-10-25T13:02:35+08:00
magick-date:modify: 2019-10-25T13:02:35+08:00
magick-pdf:HiResBoundingBox: 792x612+0+0
magick-pdf:Version: PDF-1.7\r

fsnightmckngbrd avatar Oct 25 '19 05:10 fsnightmckngbrd

Yes, your libvips has been built without PDF support. You will probably need to build libvips yourself.

What OS and version are you using?

jcupitt avatar Oct 25 '19 17:10 jcupitt

This is what I got after I run lsb_release -a Ubuntu 16.04.5 LTS

fsnightmckngbrd avatar Oct 27 '19 23:10 fsnightmckngbrd

Yes, your libvips has no PDF support. You will need to build your own libvips library.

Are you OK reading Dockerfiles? Here is a sample one for installing php-vips on Ubuntu 16.04 with PDF support.

https://github.com/jcupitt/docker-builds/blob/master/php-vips-ubuntu-16.04/Dockerfile

jcupitt avatar Oct 28 '19 11:10 jcupitt

I'm not familiar with dockerfile but I've read from google that it's just a text file that contains several commands that will be executed similar to the one that you've referenced. Do I just need to run that dockerfile? Do I need to install something like a docker engine to be able to run that file? Thanks. Btw, I have an ImageMagick installed on the server that is used by another site, will that be a conflict?

fsnightmckngbrd avatar Oct 28 '19 22:10 fsnightmckngbrd

You can use the shell commands in the dockerfile as a guide when building libvips.

First though you will need to make some choices about how you plan to install and deploy. Where will you keep the library? What kind of host will you use? How will you deploy to your servers? etc.

jcupitt avatar Oct 29 '19 09:10 jcupitt

Based on the dockerfile, I've found out that libpoppler-glib-dev is responsible for loading to pdf so I've installed it then tried re-installing the libvips and also the php-vips extension so it will detect poppler but it seems like I can't uninstall it. After uninstalling, phpinfo() still outputs that I have vips extension that doesn't support PDF load.

Not sure if there are other vips installed, I've checked the list of packages installed and there's libvips42.

I'm still planning to install it on our dev server which has an OS Ubuntu 16.04. I want to keep the library as similar to when it is installed through apt-get if possible. I'm still not familiar with linux servers so I'm having a hard time.

fsnightmckngbrd avatar Oct 29 '19 22:10 fsnightmckngbrd

It sounds like you are on the right track.

By default, libvips will install to /usr/local, the standard area for locally-installed packages. You also have a libvips installed to /usr, the system area, with apt. Your php is picking up the system libvips (with no PDF support) and cannot see your locally installed version.

I would:

  1. Uninstall the system libvips with apt remove libvips42
  2. Set the environment variable PKG_CONFIG_PATH so that pecl can find your local libvips with export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig.
  3. Verify that you have it set correctly by entering pkg-config vips --modversion .. hopefully you'll see the correct libvips version number and not get an error.
  4. Use pecl to install the libvips extension, and add the extension=.. thing. You should do this in mods-available and make a symlink to apache2, I expect you are doing this already, or pecl might even do it for you.
  5. Make your system check /usr/local/lib for shared libraries. It probably does this already, so just fingers crossed and hope on this one.
  6. Update the library cache with sudo ldconfig.
  7. Try php_info() again.
  8. If it fails, check the logs and it's probably step 5.) above.

Phew!

jcupitt avatar Oct 31 '19 09:10 jcupitt

Okay, see here's what I did these past few days.

  1. Watched tutorial on how to use docker, after that I built a Dockerfile similar to yours to an image and run it but I encountered an error Can't create a docker image for COPY failed: stat /var/lib/docker/tmp/docker-builder error

  2. Uninstalled libvips42 and re-install vips but still no PDF support.

This is so tough for someone like me who doesn't have experiences using linux environment :(

fsnightmckngbrd avatar Nov 04 '19 02:11 fsnightmckngbrd

Oh dear, I'm sorry you are having such a hard time. It's honestly straightforward and logical, but you have jumped into the deep end and it must be tricky without a *nix background.

Like all debugging, you need to go through the process slowly, step by step, and test for problems at each point.

I would only use docker if you plan to deploy using a docker container -- I just mentioned the dockerfile as a guide to what you need to do. Assuming you don't want to deploy in docker, here are the steps to follow:

First: you need to reset your system. Do you have other packages installed to /usr/local? If it's only libvips, you can simply remove /usr/local and it'll all be gone. Also remove the libvips you installed with apt. Verify that everything has gone by entering vips in the terminal. Hopefully you'll see an error message.

Now get a fresh copy of the libvips source code. Remove any old vips-8.3.3 directory and untar a new one with tar xf vips-8.3.3.tar.gz.

cd to that directory and run ./configure. Examine the output carefully. There's a big table at the end summarizing what configure found. Check that PDF support is turned on. Copy-paste that summary into this issue and we can check it together.

jcupitt avatar Nov 04 '19 10:11 jcupitt

... so you should see this in the final summary table for ./configure:

PDF import with PDFium 			no
PDF import with poppler-glib: 		yes
  (requires poppler-glib 0.16.0 or later)

Plus a lot of other stuff too, of course. I'd also check that jpg and exif have been detected.

jcupitt avatar Nov 04 '19 14:11 jcupitt

Hello, seems like I finally installed it. So what I did was follow the dockerfile. I manually installed all the libraries included on the dockerfile, then I copied the bash file (install-vips.sh) that was included on the dockerfile. I ran the bash file then it successfully installed. I now have a vips version 8.8.3 and I checked the phpinfo(), I saw PDF support "yes". I'll update you again once I have tried the vips on php as I've got to go home :)

Thank you for your patience. Gladly appreciate it.

fsnightmckngbrd avatar Nov 06 '19 07:11 fsnightmckngbrd

Well done!

jcupitt avatar Nov 06 '19 11:11 jcupitt

Okay so it's now working. Conversion is fast than Imagick but the server still hangs while the conversion is on-going. I have 32 pdf file with a total of 95 pages altogether. Should I open another issue and close this one? Thanks!

fsnightmckngbrd avatar Nov 06 '19 22:11 fsnightmckngbrd

Could you explain what you mean by "the server still hangs"?

If you press a button on the page to start conversion, then unless you design your web application to process in the background, that page will be unresponsive until the conversion is finished.

However, if you connect to the server from another tab, you should be able to view pages while the conversion takes place.

So ... do you really see the server hang, or is it just the page where you do the conversion?

jcupitt avatar Nov 11 '19 09:11 jcupitt

I'm connecting through other tabs. I'm not sure what's the cause.

fsnightmckngbrd avatar Nov 12 '19 03:11 fsnightmckngbrd

You could ssh to the server and watch top while your request executes. It shouldn't be using much memory, and there should be idle httpd workers.

Is this apache? You could check the number of workers. It's usually five, I think. I'd be very surprised if someone has reduced it to one.

jcupitt avatar Nov 12 '19 09:11 jcupitt

Yes, this is apache. So I monitored top while the request executes and I saw that apache2 cpu usage is too much. It even goes till 90% and up, probably the reason why the server hangs.

I researched how to check number of workers but I got lost :D What I did was I went to the apache directory. Checked the mods-enabled folder and found out that the mpm I'm using is prefork. I read the conf file of prefork and here is the image. https://pasteboard.co/IGp4WXD.png

I also checked phpinfo(), thread safety is disabled. Will that be a problem?

fsnightmckngbrd avatar Nov 12 '19 22:11 fsnightmckngbrd