Note:
Php installation directory:/usr/local/php5
Php. ini configuration file path:/usr/local/php5/etc/php. ini
Nginx installation directory:/usr/local/nginx
Nginx website root directory:/usr/local/nginx/html
1. Install the compilation tool
Yum install wget make gcc-c ++ gtk +-devel zlib-devel openssl-devel pcre-devel kernel keyutils patch perl
2. Install ImageMagick
System O & M www.111cn.net reminder: qihang01 original content is copyrighted. For reprinting, please indicate the source and original link.
Cd/usr/local/src # enter the package storage directory
Wget http://www.imagemagick.org/download/ImageMagick.tar.gz # Download ImageMagick
Tar zxvf ImageMagick.tar.gz # decompress
Cd ImageMagick-6.7.9-3 # enter the installation directory
./Configure -- prefix =/usr/local/imagemagick # configuration
Make # compile
Make install # install
Export PKG_CONFIG_PATH =/usr/local/imagemagick/lib/pkgconfig/# set environment variables
3. Install imagick
Cd/usr/local/src
Wget http://pecl.php.net/get/imagick-3.0.1.tgz # Download imagick
Tar zxvf imagick-3.0.1.tgz
Cd imagick-3.0.1
/Usr/local/php5/bin/phpize # use phpize to generate the configure configuration file
./Configure -- with-php-config =/usr/local/php5/bin/php-config -- with-imagick =/usr/local/imagemagick # configuration
Make # compile
Make install # install
Note: an error occurs during installation. This error is generally caused by the lack of a compilation toolkit. Follow the prompts to install the corresponding toolkit by referring to the first step.
After the installation is complete, the following interface appears. Remember the following path, which will be used later.
Installing shared extensions:/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/# imagick module path
4. Configure php to support imagick
Vi/usr/local/php5/etc/php. ini # Edit the configuration file and add the following content in the last line:
Extension = "imagick. so"
5. Test
Vi/usr/local/nginx/html/phpinfo. php # Edit and enter the following code:
<? Php
Phpinfo ();
?>
Wq! # Save and exit
Vi/usr/local/nginx/html/imagick. php # Edit and enter the following code:
<? Php
Header ('content-type: image/jpeg ');
$ Image = new Imagick ('www .111cn.net. jpg ');
// If 0 is provided as a width or height parameter,
// Aspect ratio is maintained
$ Image-> thumbnailImage (300,225 );
Echo $ image;
?>
Upload an image www.111cn.net. jpg (the size is 640*480) under the root directory/usr/local/nginx/html/of the website, as shown in the following figure.
Service php-fpm restart # restart php-fpm
Service nginx restart # restart nginx
Open phpinfo. php in the browser, as shown in the following figure. The imagick information is displayed.
Open imagick. php in the browser, as shown in the following figure. The original image is reduced to 300*225.
In the terminal command line, enter:
/Usr/local/imagemagick/bin/convert www.111cn.net. jpg-resize 50% www.111cn.net. png # generate a new image with the original image size of 50%
The original image www.111cn.net. jpg is 640*480, and the generated image www.111cn.net. png is 320*240, which is half the size of the original image! As shown in the following figure:
Now, the installation of imagick in php in Linux is complete!