I'm wondering how we could add the php extension pdflib to the ddev's web container?
Asked
Active
Viewed 39 times
1 Answers
1
With the thankful help of rfay we got an solution for it (and maybe also applicable to other php extensions as well):
- 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. - 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 theDockerfile
- 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.

alpham8
- 1,314
- 2
- 14
- 32
-
Note that this solution works for AMD64 machines, but for arm64 machines like Apple Silicon, you'll need to use the arm64 version ("Linux ARM64 (aarch64)"), apparently from https://www.pdflib.com/binaries/PDFlib/1001/PDFlib-10.0.1-Linux-aarch64-php.tar.gz – rfay Jul 06 '23 at 12:15