Solutions for ImagickExceptions in nextcloud.log
ImagickExceptions in nextcloud.log
You are in trouble with previews and/or with thumbnails within your Nextcloud?
You found errors like “ImagickException: not authorized…” in your Nextcloud logfile (/var/nc_data/nextcloud.log)?
Just follow these instructions in your terminal session (e.g. ssh) and solve these “Imagick” issues yourself:
Error messages e.g.:
tail -f /var/nc_data/nextcloud.log | grep -i imagickexception
... ...ImagickException: not authorized `/upload_tmp/oc_tmp_zCg8T6-.d1539116135' @ error/constitute.c/ReadImage/412 ...ImagickException: not authorized `/upload_tmp/oc_tmp_BiLdF7-.pdf' @ error/constitute.c/ReadImage/412 ...
Solution 1:
sudo -s (or su -) apt install ghostscript -y ln -s /usr/local/bin/gs /usr/bin/gs cp /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml.bak sed -i "s/rights\=\"none\" pattern\=\"PS\"/rights\=\"read\|write\" pattern\=\"PS\"/" /etc/ImageMagick-6/policy.xml sed -i "s/rights\=\"none\" pattern\=\"EPI\"/rights\=\"read\|write\" pattern\=\"EPI\"/" /etc/ImageMagick-6/policy.xml sed -i "s/rights\=\"none\" pattern\=\"PDF\"/rights\=\"read\|write\" pattern\=\"PDF\"/" /etc/ImageMagick-6/policy.xml sed -i "s/rights\=\"none\" pattern\=\"XPS\"/rights\=\"read\|write\" pattern\=\"XPS\"/" /etc/ImageMagick-6/policy.xml service php7.3-fpm restart && service nginx restart
Solution 2 (necessary on DEBIAN 9.5 only so far?!):
su - apt install ghostscript -y ln -s /usr/local/bin/gs /usr/bin/gs cp /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml.bak && vi /etc/ImageMagick-6/policy.xml
add the following four rows to the end of the file before the </policymap>:
[...] <policy domain="coder" rights="read|write" pattern="PS" /> <policy domain="coder" rights="read|write" pattern="EPI" /> <policy domain="coder" rights="read|write" pattern="PDF" /> <policy domain="coder" rights="read|write" pattern="XPS" /> </policymap>
Then restart all services:
service php7.3-fpm restart && service nginx restart
Enjoy your personal data in your secured and hardened Nextcloud.
Don’t forget to backup your Nextcloud
Find more instructions here: Nextcloud Backup and Restore