How to add the pdflib extension in ddev's web container?

183 Views Asked by At

I'm wondering how we could add the php extension pdflib to the ddev's web container?

1

There are 1 best solutions below

1
alpham8 On

With the thankful help of rfay we got an solution for it (and maybe also applicable to other php extensions as well):

  1. Refer to https://www.pdflib.com/download/pdflib-product-family/ which pdflib version fits to you current PHP version. Also, the right build number of PHP is needed here. You can find out the right extension build number by creating a simple phpinfo(); php script. Please note, that it's important that you access the script through the web browser, because i. e. the PHP CLI settings can possibly differ from the ones used under in the web server.
  2. Then change the lines accordingly to refer to the right download links, as well as the right build number to fit in this line: RUN cp ./PDFlib-10.0.0p1-Linux-x64-php/bind/php/php-810-nts/php_pdflib.so /usr/lib/php/20210902/php_pdflib.so. Below the full example using PHP 7.4 under FPM for the file <project-root>/.ddev/web-build/Dockerfile:
# You can copy this Dockerfile.example to Dockerfile to add configuration
# or packages or anything else to your webimage
ARG BASE_IMAGE
FROM $BASE_IMAGE
RUN cd /tmp/
RUN wget https://www.pdflib.com/binaries/PDFlib/1000/PDFlib-10.0.0p1-Linux-x64-php.tar.gz
RUN tar xfz ./PDFlib-10.0.0p1-Linux-x64-php.tar.gz
RUN cp ./PDFlib-10.0.0p1-Linux-x64-php/bind/php/php-810-nts/php_pdflib.so /usr/lib/php/20210902/php_pdflib.so
RUN echo "extension=php_pdflib.so" > /etc/php/8.1/mods-available/php_pdflib.ini
RUN ln -s /etc/php/8.1/mods-available/php_pdflib.ini /etc/php/8.1/fpm/conf.d/php_pdflib.ini
RUN ln -s /etc/php/8.1/mods-available/php_pdflib.ini /etc/php/8.1/cli/conf.d/php_pdflib.ini

Some additional nodes:

  • ddev uses Ubuntu Linux, meaning in case of PHP, this distribution makes use of splitting up PHP's ini files per extension instead of having all extensions in one ini file.
  • test the commands line per line using ddev ssh before you place it in the Dockerfile
  • ddev will create automatically the folder <project-root>/.ddev/web-build for you. If it's not present, you might need to start your ddev project initially and then it gets created.