Nerd Tutorials

How Compile and build a package to PHP for UBUNTU

I was using aaPanel for server management. aaPanel keep php in some isolated folder (/www/server/php/74 last digit for php version for me php7.4) for keeping different version of PHP , aaPanel provide readymade extension install as like below

aaPanel extension installation popup

But this readymade screen doesn't provide not all extension, Here i will give demonstrate how to install Imagemagick in ubuntu

  1. first login to ssh using terminal/putty

2. login as root

sudo su

3. Install ImageMagic

$ sudo apt install imagemagick

4.Install dev install pack for configuration

$ sudo apt-get install libmagickwand-6-headers libmagickwand-dev libmagickwand-6.q16-dev

Check imageMagic installation

identify -version

6. Download ImageMagic PHP from PCL http://pecl.php.net/package/imagick

wget http://pecl.php.net/package/imagick

7. Extract source file (My version is imagick 3.7.0)

tar -zxvf imagick-3.7.0.tgz

8. Open source code folder

cd imagick-3.7.0

9. prepare the build environment for a PHP extension by using phpize ( below path is my php installation directory)

/www/server/php/74/bin/phpize

10. Configure source code for installation

./configure --with-php-config=/www/server/php/74/bin/php-config

11. Install / Compile php-Imagic

make

//make install

12. copy compiled .so binary to extension folder. (i put exact file path)

cp -p /tmp/imagick-3.7.0/modules/imagick.so /www/server/php/74/lib/php/extensions/no-debug-non-zts-20180731/

13. enable extension in php.ini configuration file

14. restart php or apache

service apache2 restart

15. If you are trying to use pdf or other ghost script imagemagick block operation by using default setting s , so here i am trying to convert a pdf file to image , i may get following error

root@machine $ convert -density 300 -depth 8 -quality 90 input_file.pdf output_files.png
convert: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.

So i must change configuration file to enable it by editing /etc/ImageMagick-7/policy.xml

nano /etc/ImageMagick-7/policy.xml
edit 
<policy domain="coder" rights="none" pattern="PDF" /> to
<policy domain="coder" rights="read | write" pattern="PDF" />


or add following line before </policymap> 
<policy domain="coder" rights="read | write" pattern="PDF" />

Exit mobile version