如何在ddev的Web容器中添加pdflib扩展?

huangapple go评论58阅读模式
英文:

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

问题

我在想如何将php扩展pdflib添加到ddev的web容器中?

英文:

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

答案1

得分: 1

rfay的帮助下,我们找到了一个解决方法(也可能适用于其他PHP扩展):

  1. 请参考 https://www.pdflib.com/download/pdflib-product-family/,确定适用于您当前PHP版本的pdflib版本。此外,还需要正确的PHP构建编号。您可以通过创建一个简单的 phpinfo(); PHP脚本来找到正确的扩展构建编号。请注意,通过Web浏览器访问脚本非常重要,因为PHP CLI设置可能与Web服务器中使用的设置不同。
  2. 然后根据正确的下载链接和构建编号更改相应的行,以适应以下行:RUN cp ./PDFlib-10.0.0p1-Linux-x64-php/bind/php/php-810-nts/php_pdflib.so /usr/lib/php/20210902/php_pdflib.so。以下是在PHP 7.4下使用FPM的完整示例,用于文件 <project-root>/.ddev/web-build/Dockerfile
# 您可以将此Dockerfile.example复制到Dockerfile,以添加配置、包或其他内容到您的web镜像
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

一些额外的注意事项:

  • ddev使用Ubuntu Linux,这意味着在PHP的情况下,该发行版会将PHP的ini文件拆分为每个扩展一个ini文件,而不是将所有扩展放在一个ini文件中。

  • 在将其放入 Dockerfile 之前,使用 ddev ssh 逐行测试这些命令。

  • ddev会自动为您创建文件夹 <project-root>/.ddev/web-build。如果不存在,您可能需要首先启动您的ddev项目,然后它将被创建。

英文:

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 &lt;project-root&gt;/.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 &quot;extension=php_pdflib.so&quot; &gt; /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 &lt;project-root&gt;/.ddev/web-build for you. If it's not present, you might need to start your ddev project initially and then it gets created.

huangapple
  • 本文由 发表于 2023年7月6日 15:40:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76626537.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定