Centos+PHP模块+exif扩展 (第三方模块)
今日应开发需求,想要显示图片的属性信息,于是度娘就告知exif模块可以实现,操作步骤与问题总结吐下;
php安装扩展的几种方法注意与Apache+PHP或者Nginx+PHP的运行模式不同,WorkerMan是基于PHP命令行PHP CLI运行的,使用的是不同的PHP可执行程序,使用的php.ini文件也可能不同。所以在网页中打印phpinfo()
看到安装了某个扩展,不代表命令行的PHP CLI也安装了对应的扩展。
运行php -m
会列出命令行 PHP CLI 已经安装的扩展,结果类似如下:
~#php-m[PHPModules]libeventposixpcntl...如何确定PHP CLI 的php.ini文件的位置
当我们安装扩展时,可能需要手动配置php.ini文件,把扩展加进去,所以要确认PHP CLI的php.ini文件的位置。可以运行php --ini
查找PHP CLI的ini文件位置,结果类似如下(各个系统显示结果会有差异):
~#php--iniConfigurationFile(php.ini)Path:/etc/php5/cliLoadedConfigurationFile:/etc/php5/cli/php.iniScanforadditional.inifilesin:/etc/php5/cli/conf.dAdditional.inifilesparsed:/etc/php5/cli/conf.d/apc.ini,/etc/php5/cli/conf.d/libevent.ini,/etc/php5/cli/conf.d/memcached.ini,/etc/php5/cli/conf.d/mysql.ini,/etc/php5/cli/conf.d/pdo.ini,/etc/php5/cli/conf.d/pdo_mysql.ini...给PHP CLI安装扩展(安装memcached扩展为例)方法一、使用apt或者yum命令安装
如果PHP是通过 apt 或者 yum 命令安装的,则扩展也可以通过 apt 或者 yum 安装
debian/ubuntu等系统apt安装PHP扩展方法(非root用户需要加sudo命令)
1、利用apt-cache search
查找扩展包
~#apt-cachesearchmemcachedphpphp-apc-APC(AlternativePHPCache)moduleforPHP5php5-memcached-memcachedmoduleforphp5
2、使用apt-get install
安装扩展包
~#apt-getinstall-yphp5-memcachedReadingpackagelists...DoneReadingstateinformation...Done...
centos等系统yum安装PHP扩展方法
1、利用yum search
查找扩展包
~#yumsearchmemcachedphpphp-pecl-memcached-memcachedmoduleforphp5
2、使用yum install
安装扩展包
~#yuminstall-yphp-pecl-memcachedReadingpackagelists...DoneReadingstateinformation...Done...
说明:
使用apt或者yum安装PHP扩展会自动配置php.ini文件,安装完直接可用,十分方便。缺点是有些扩展在apt或者yum中没有对应的扩展安装包。
方法二、使用pecl安装使用pecl install
命令安装扩展
1、pecl install
安装
~#peclinstallmemcacheddownloadingmemcached-2.2.0.tgz...Startingtodownloadmemcached-2.2.0.tgz(70,449bytes)....方法三、使用phpzip安装模块
一、环境介绍
[root@ghzz~]#cat/etc/redhat-releaseCentOSrelease6.5(Final)Youhavenewmailin/var/spool/mail/root[root@ghzz~]#php-vZendGuardLoaderrequiresZendEngineAPIversion220121212.TheZendEngineAPIversion220131226whichisinstalled,isnewer.ContactZendTechnologiesathttp://www.zend.com/foralaterversionofZendGuardLoader.PHP5.6.14(cli)(built:Jul7201612:43:11)Copyright(c)1997-2015ThePHPGroupZendEnginev2.6.0,Copyright(c)1998-2015ZendTechnologieswithZendOPcachev7.0.6-dev,Copyright(c)1999-2015,byZendTechnologies
二、查找模块
方法一:去php安装路径下ext目录下都是模块
cd /root/software/php-5.6.14/ext/exif
如果找不到find./-typed-name"php*"去查找
###这个模块,应该是php安装包内自带的,但是./configure编译安装的时候没有加载的包
方法二:php官网
PHP官网地址:http://pecl.php.net/packages.php
三、编译安装 (加载模块)
1)进入php存储模块目录
[root@ghzzlsolesen-pel-56d1b7f]#cd/root/software/php-5.6.14/ext/exif##测试环境##如果找不到find./-typef-name"php-*"去查找[root@ghzzexif]#ll总用量196-rw-r--r--1100010003339月302015config.m4-rw-r--r--1100010003089月302015config.w32-rw-r--r--110001000369月302015CREDITS-rw-r--r--1100010004969月302015example.php-rw-r--r--1100010001453319月302015exif.c-rw-r--r--11000100049339月302015exif.dsp-rw-r--r--11000100019539月302015package.xml-rw-r--r--11000100014639月302015php_exif.h-rw-r--r--110001000299月302015test.phpdrwxr-xr-x21000100040969月302015tests-rw-r--r--110001000112329月302015test.txt
2)使用phpize添加php动态模块
作用:使用phpize生成
[root@ghzzexif]#/usr/local/php/bin/phpizeConfiguringfor:PHPApiVersion:20131106ZendModuleApiNo:20131226ZendExtensionApiNo:220131226[root@ghzzexif]#./configure-with-php-config=/usr/local/php/bin/php-configcheckingforgrepthathandleslonglinesand-e.../bin/grep#。。。省略若干字段checkingwhetherstrippinglibrariesispossible...yescheckingiflibtoolsupportssharedlibraries...yescheckingwhethertobuildsharedlibraries...yescheckingwhethertobuildstaticlibraries...nocreatinglibtoolappendingconfigurationtag"CXX"tolibtoolconfigure:creating./config.statusconfig.status:creatingconfig.h[root@ghzzexif]#make&&makeinstall/bin/sh/root/software/php-5.6.14/ext/exif/libtool--mode=compilecc-I.-I/root/software/php-5.6.14/ext/exif-DPHP_ATOM_INC-I/root/software/php-5.6.14/ext/exif/include-I/root/software/php-5.6.14/ext/exif/main-I/root/software/php-5.6.14/ext/exif-I/usr/local/php/include/php-I/usr/local/php/include/php/main-I/usr/local/php/include/php/TSRM-I/usr/local/php/include/php/Zend-I/usr/local/php/include/php/ext-I/usr/local/php/include/php/ext/date/lib-DHAVE_CONFIG_H-g-O2-c/root/software/php-5.6.14/ext/exif/exif.c-oexif.lomkdir.libscc-I.-I/root/software/php-5.6.14/ext/exif-DPHP_ATOM_INC-I/root/software/php-5.6.14/ext/exif/include-I/root/software/php-5.6.14/ext/exif/main-I/root/software/php-5.6.14/ext/exif-I/usr/local/php/include/php-I/usr/local/php/include/php/main-I/usr/local/php/include/php/TSRM-I/usr/local/php/include/php/Zend-I/usr/local/php/include/php/ext-I/usr/local/php/include/php/ext/date/lib-DHAVE_CONFIG_H-g-O2-c/root/software/php-5.6.14/ext/exif/exif.c-fPIC-DPIC-o.libs/exif.o/bin/sh/root/software/php-5.6.14/ext/exif/libtool--mode=linkcc-DPHP_ATOM_INC-I/root/software/php-5.6.14/ext/exif/include-I/root/software/php-5.6.14/ext/exif/main-I/root/software/php-5.6.14/ext/exif-I/usr/local/php/include/php-I/usr/local/php/include/php/main-I/usr/local/php/include/php/TSRM-I/usr/local/php/include/php/Zend-I/usr/local/php/include/php/ext-I/usr/local/php/include/php/ext/date/lib-DHAVE_CONFIG_H-g-O2-oexif.la-export-dynamic-avoid-version-prefer-pic-module-rpath/root/software/php-5.6.14/ext/exif/modulesexif.locc-shared.libs/exif.o-Wl,-soname-Wl,exif.so-o.libs/exif.socreatingexif.la(cd.libs&&rm-fexif.la&&ln-s../exif.laexif.la)/bin/sh/root/software/php-5.6.14/ext/exif/libtool--mode=installcp./exif.la/root/software/php-5.6.14/ext/exif/modulescp./.libs/exif.so/root/software/php-5.6.14/ext/exif/modules/exif.socp./.libs/exif.lai/root/software/php-5.6.14/ext/exif/modules/exif.laPATH="$PATH:/sbin"ldconfig-n/root/software/php-5.6.14/ext/exif/modules----------------------------------------------------------------------Librarieshavebeeninstalledin:/root/software/php-5.6.14/ext/exif/modulesIfyoueverhappentowanttolinkagainstinstalledlibrariesinagivendirectory,LIBDIR,youmusteitheruselibtool,andspecifythefullpathnameofthelibrary,orusethe`-LLIBDIR'flagduringlinkinganddoatleastoneofthefollowing:-addLIBDIRtothe`LD_LIBRARY_PATH'environmentvariableduringexecution-addLIBDIRtothe`LD_RUN_PATH'environmentvariableduringlinking-usethe`-Wl,--rpath-Wl,LIBDIR'linkerflag-haveyoursystemadministratoraddLIBDIRto`/etc/ld.so.conf'Seeanyoperatingsystemdocumentationaboutsharedlibrariesformoreinformation,suchastheld(1)andld.so(8)manualpages.----------------------------------------------------------------------Buildcomplete.Don'tforgettorun'maketest'.Installingsharedextensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/[root@ghzzexif]#vi/usr/local/php/etc/php.ini##如果文件路径不存在,就去安装目录查找php.ini文件查找:extension=再最后一个extension=后面添加上extension=“exif.so”[root@ghzzext]#grep-n"exif.so"/usr/local/php/etc/php.ini743:extension="exif.so"[root@ghzzexif]#/etc/init.d/php-fpmrestart##重启加载php模块
四、此时可能出现模块加载报错
Gracefullyshuttingdownphp-fpm.doneStartingphp-fpm[06-Jan-201713:43:43]NOTICE:PHPmessage:PHPWarning:PHPStartup:Invalidlibrary(maybenotaPHPlibrary)‘fileinfo.so’inUnknownonline0重新执行上面的操作还是一直报这个错误
解决方法
到你的模块安装目录,我这里是:
cd/****/soft/lnmp1.2-full/src/php-5.6.14/ext/exifmakeclean
在重新执行上面的全部命令,安装就成功了
报错原因:
因为之前编译的库文件.so存在异常,所以没有将新的写入,有冲突,需要清空后重新编译,即可启动
五、检查模块运行情况及效果
[root@ghzzext]#php-m|grepexifexif
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。