Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sirhxalot's avatar

Laravel Sail + Imagick + Security Policy

Hi folks!

I am working with Laravel Sail (^1.0.1) and need to install the Imagick Library. Therefore I have published the dockerfiles.

Adding Imagick is not the problem I just add the dependency to my docker/8.1/Dockerfile (last line):

...
RUN apt-get update \
    && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
    && mkdir -p ~/.gnupg \
    && chmod 600 ~/.gnupg \
    && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
    && apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
    && apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
    && echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu impish main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
    && apt-get update \
    && apt-get install -y php8.1-cli php8.1-dev \
       php8.1-pgsql php8.1-sqlite3 php8.1-gd \
       php8.1-curl \
       php8.1-imap php8.1-mysql php8.1-mbstring \
       php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap \
       php8.1-intl php8.1-readline \
       php8.1-ldap \
       php8.1-msgpack php8.1-igbinary php8.1-redis php8.1-swoole \
       php8.1-memcached php8.1-pcov php8.1-xdebug \
       php8.1-imagick \
...

And build the docker container: vendor/bin/sail build --no-cache

But I need to convert a PDF to an image - therefore I am using Spatie's PDF to Image

When I try to convert the PDF the following exception will be thrown: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/421

I have tried the following:

ARG imagemagic_config=/etc/ImageMagick/policy.xml

RUN if [ -f $imagemagic_config ] ; then sed -i 's/<policy domain="coder" rights="none" pattern="PDF" \/>/<policy domain="coder" rights="read|write" pattern="PDF" \/>/g' $imagemagic_config ; else echo did not see file $imagemagic_config ; fi

But it didn't work.

Does somebody know how to add the policy?

And here is a little site question: Do you know how to list the files in the system? - I am looking for somthing like ls -a?

Any help is appreciated!

Best regards Sirthxalot

0 likes
3 replies
kimsal's avatar

Did you ever fix this? I'm hitting the exact same issue, but... can't get it. It's strange, because I was past this some time ago, I think. Same code was working for a long time. Have had to rebuild some images - same docker files - but now it's not working. The 'sed' thing is what i use on server install/setup (via a forge recipe) but having this work on image build with sail isn't cutting the mustard.

VoordeMensen's avatar

Not sure how safe but this works:

ARG imagemagic_config=/etc/ImageMagick-6/policy.xml
RUN rm $imagemagic_config

Note: ImageMagick-6 as the directory may also help you

Please or to participate in this conversation.