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

php-vips has not been configured for PDF support #31

Open
fsnightmckngbrd opened this issue Oct 24, 2019 · 19 comments
Open

php-vips has not been configured for PDF support #31

fsnightmckngbrd opened this issue Oct 24, 2019 · 19 comments
Labels

Comments

@fsnightmckngbrd
Copy link

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!

@jcupitt
Copy link
Member

jcupitt commented Oct 25, 2019

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

@fsnightmckngbrd
Copy link
Author

fsnightmckngbrd commented Oct 25, 2019

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

@jcupitt
Copy link
Member

jcupitt commented Oct 25, 2019

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

What OS and version are you using?

@fsnightmckngbrd
Copy link
Author

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

@jcupitt
Copy link
Member

jcupitt commented Oct 28, 2019

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

@fsnightmckngbrd
Copy link
Author

fsnightmckngbrd commented Oct 28, 2019

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?

@jcupitt
Copy link
Member

jcupitt commented Oct 29, 2019

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.

@fsnightmckngbrd
Copy link
Author

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.

@jcupitt
Copy link
Member

jcupitt commented Oct 31, 2019

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!

@fsnightmckngbrd
Copy link
Author

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 :(

@jcupitt
Copy link
Member

jcupitt commented Nov 4, 2019

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
Copy link
Member

jcupitt commented Nov 4, 2019

... 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.

@fsnightmckngbrd
Copy link
Author

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.

@jcupitt
Copy link
Member

jcupitt commented Nov 6, 2019

Well done!

@fsnightmckngbrd
Copy link
Author

fsnightmckngbrd commented Nov 6, 2019

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!

@jcupitt
Copy link
Member

jcupitt commented Nov 11, 2019

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?

@fsnightmckngbrd
Copy link
Author

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

@jcupitt
Copy link
Member

jcupitt commented Nov 12, 2019

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.

@fsnightmckngbrd
Copy link
Author

fsnightmckngbrd commented Nov 12, 2019

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?

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

No branches or pull requests

2 participants