imagick是一個PHP擴展,是一套軟件系列,用ImageMagick提供API來進行圖片的建立與修改,不過這些操做已經包裝到擴展imagick中去了,最終調用的是ImageMagick提供的API
ImageMagick主要用於圖片的建立、編輯以及轉換等,ImageMagick與GD的性能要高不少,若是是在處理大量的圖片時更加能體現ImageMagick的性能。php
下面介紹下安裝php的imagick擴展模塊的方法:html
1)下載軟件
下載ImageMagick.tar.gz:https://www.imagemagick.org/download/
下載imagick-3.1.0RC1.tgz: http://pan.baidu.com/s/1hsHiEUg (提取密碼:dqu2)mysql
1、安裝php的imagick擴展模塊第一種方法:(pcel安裝imagick)【推薦第一種方法】nginx
2)安裝ImageMagickweb
[root@dev software]# tar -xzvf ImageMagick.tar.gz
[root@dev software]# cd ImageMagick-7.0.2-0
[root@dev ImageMagick-7.0.2-0]# ./configure --prefix=/usr/local/imagemagick
[root@dev ImageMagick-7.0.2-0]# make && make installsql
[root@dev ImageMagick-7.0.2-0]# /Data/app/php5.6.26/bin/pecl install imagickvim
................
Build process completed successfully
Installing '/Data/app/php5.6.26/lib/php/extensions/no-debug-non-zts-20131226/imagick.so'
Installing '/Data/app/php5.6.26/include/php/ext/imagick/php_imagick_shared.h'
install ok: channel://pecl.php.net/imagick-3.4.3RC1
configuration option "php_ini" is not set to php.ini location
You should add "extension=imagick.so" to php.inibash
產生的imagick.so文件拷貝到/Data/app/php5.6.26/lib/php/extensions/no-debug-non-zts-20131226下
在php.ini文件裏添加imagick.so
而後重啓php加載imagick模塊便可。
使用/Data/app/php5.6.26/bin/php -m 命令查看加載的模塊服務器
2、安裝php的imagick擴展模塊第二種方法:(編譯安裝imagick)
3)安裝Imagick
注:安裝該擴展不要求安裝ImageMagick
[root@dev software]# tar -xzvf imagick-3.1.0RC1
[root@dev software]# cd imagick-3.1.0RC1
[root@dev imagick-3.1.0RC1]# /Data/app/php5.6.26/bin/phpize #這裏,以前安裝的php路徑是/Data/app/php5.6.26,使用phpize生成configure編譯文件
[root@dev imagick-3.1.0RC1]# ./configure --with-php-config=/Data/app/php5.6.26/bin/php-config --with-imagick=/usr/local/imagemagick
報錯:
checking for MagickWand.h header file... configure: error: Cannot locate header file MagickWand.happ
解決辦法:
查看imagick解壓目錄下的config.m4文件,發現ImageMagick在7.0.2高版本後的目錄結構發生了變化所致使編譯失敗的。
查看config.m4的第55,56行內容:
[root@dev imagick-3.1.0RC1]# vim config.m4
.......
if test -r $WAND_DIR/include/ImageMagick/wand/MagickWand.h; then
AC_MSG_RESULT(found in $WAND_DIR/include/ImageMagick/wand/MagickWand.h)
..............................
對比ImageMagick安裝目錄結構:
[root@dev include]# pwd
/usr/local/imagemagick/include
[root@dev include]# ls
ImageMagick-7
[root@dev include]# ls ImageMagick-7/
Magick++ MagickCore Magick++.h MagickWand
發現ImageMagick安裝後目錄結構和上面imagick的config.m4文件裏的不同
須要作下軟連接:
[root@dev include]# ln -s ImageMagick-7 ImageMagick
[root@dev include]# ls
ImageMagick ImageMagick-7
[root@dev include]# cd ImageMagick
[root@dev ImageMagick]# ls
Magick++ MagickCore Magick++.h MagickWand
[root@dev ImageMagick]# ln -s MagickWand wand
[root@dev ImageMagick]# ls
Magick++ MagickCore Magick++.h MagickWand wand
這樣,再次編譯imagick就成功了!
[root@dev imagick-3.1.0RC1]# ./configure --with-php-config=/Data/app/php5.6.26/bin/php-config --with-imagick=/usr/local/imagemagick
.........
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
[root@dev imagick-3.1.0RC1]# make && make install
報錯:
make: *** [imagick_class.lo] 錯誤 1
解決:
緣由是沒有找到pkgconfig路徑
[root@dev imagick-3.1.0RC1]# find /usr -name pkgconfig
/usr/lib64/pkgconfig
/usr/share/pkgconfig
/usr/local/lib/pkgconfig
/usr/local/imagemagick/lib/pkgconfig
/usr/local/include/libmemcached/lib/pkgconfig
/usr/local/libmemcached/lib/pkgconfig
[root@dev imagick-3.1.0RC1]# export PKG_CONFIG_PATH=/usr/local/imagemagick/lib/pkgconfig
而後再次make && make install
完整的流程是:
[root@dev imagick-3.1.0RC1]# /Data/app/php5.6.26/bin/phpize
[root@dev imagick-3.1.0RC1]# export PKG_CONFIG_PATH=/usr/local/imagemagick/lib/pkgconfig
[root@dev imagick-3.1.0RC1]# ./configure --with-php-config=/Data/app/php5.6.26/bin/php-config --with-imagick=/usr/local/imagemagick
[root@dev imagick-3.1.0RC1]# make && make install
=========================================================
make install執行結果顯示:
installing shared extensions: /Data/app/php5.6.26/lib/php/extensions/no-debug-non-zts-20131226/
Installing header files: /Data/app/php5.6.26/include/php/
生成imagick.so到/Data/app/php5.6.26/lib/php/extensions/no-debug-non-zts-20131226/
手動將imagick.so添加到php.ini文件裏,
[root@dev etc]# pwd
/Data/app/php5.6.26/etc
[root@dev etc]# vim php.ini
............
extension="/Data/app/php5.6.26/lib/php/extensions/no-debug-non-zts-20131226/imagick.so"
而後重啓php和nginx便可!
[root@dev etc]# /Data/app/php5.6.26/bin/php -m
.....
imagick
php升級:由php5.5.1升級到php5.6.26
因爲線上服務器最初部署的php環境版本是5.5.1,後續應開發需求,將其升級到5.6.26版本
下面附上本身的升級腳本:
[root@huanqiu_web1 software]# pwd
/software/software
[root@huanqiu_web1 software]# ls #下載升級須要的軟件
ImageMagick.tar.gz install_php.sh memcached-2.2.0.tgz php-5.6.26.tar.gz php-wkhtmltox-master.zip
[root@huanqiu_web1 software]# cat install_php.sh #升級腳本(下面編譯時帶的mysql參數,mysql安裝後能夠不啓動,這裏編譯須要跟上mysql參數)
#!/bin/bash
cd /software/software
tar -xvf php-5.6.26.tar.gz
cd php-5.6.26
./configure --prefix=/Data/app/php5.6.26 --with-curl --enable-mbstring --with-mysqli=/Data/app/mysql5.6.25/bin/mysql_config --with-mysql=/Data/app/mysql5.6.25/ --disable-rpath --enable-inline-optimization --with-pcre-regex --with-config-file-path=/Data/app/php5.6.26/etc/ --with-config-file-scan-dir=/Data/app/php5.6.26/etc/php.d --with-gd --enable-soap --with-pdo-mysql=/Data/app/mysql5.6.25/ --with-freetype-dir --with-png-dir --with-mcrypt --with-zlib --with-jpeg-dir --with-iconv=/usr/local/lib/ --enable-fpm
make && make install
###extension####
cd /software/software
tar -xvf ImageMagick.tar.gz
cd ImageMagick-7.0.2-0
./configure
make
make install
/Data/app/php5.6.26/bin/pecl install imagick
cd /software/software
tar -xvf memcached-2.2.0.tgz
cd memcached-2.2.0
/Data/app/php5.6.26/bin/phpize
./configure --with-php-config=/Data/app/php5.6.26/bin/php-config
make && make install
cd /software/software
unzip php-wkhtmltox-master.zip
cd php-wkhtmltox-master
/Data/app/php5.6.26/bin/phpize
./configure --with-php-config=/Data/app/php5.6.26/bin/php-config
make && make install
cd /software/software/php-5.6.26/ext/sockets
/Data/app/php5.6.26/bin/phpize
./configure --with-php-config=/Data/app/php5.6.26/bin/php-config
make && make install
cd /software/software/php-5.6.26/ext/bcmath
/Data/app/php5.6.26/bin/phpize
./configure --with-php-config=/Data/app/php5.6.26/bin/php-config
make && make install
cd /software/software/php-5.6.26/ext/gettext
/Data/app/php5.6.26/bin/phpize
./configure --with-php-config=/Data/app/php5.6.26/bin/php-config
make && make install
cd /software/software/php-5.6.26/ext/openssl
mv config0.m4 config.m4
/Data/app/php5.6.26/bin/phpize
./configure --with-php-config=/Data/app/php5.6.26/bin/php-config
make && make install
cp /Data/app/php5.5.1/etc/php-fpm.conf /Data/app/php5.6.26/etc/
cp /Data/app/php5.5.1/etc/php.ini /Data/app/php5.6.26/etc/
sed -i 's#/Data/app/php5.5.1/lib/php/extensions/no-debug-non-zts-20121212/#/Data/app/php5.6.26/lib/php/extensions/no-debug-non-zts-20131226/#g' /Data/app/php5.6.26/etc/php.ini
sed -i '/memcached.so/i extension="/Data/app/php5.6.26/lib/php/extensions/no-debug-non-zts-20131226/imagick.so"' /Data/app/php5.6.26/etc/php.ini