Centos+PHP模块+exif扩展 (第三方模块)
admin
2023-06-17 12:21:50
0

今日应开发需求,想要显示图片的属性信息,于是度娘就告知exif模块可以实现,操作步骤与问题总结吐下;

php安装扩展的几种方法

注意

与Apache+PHP或者Nginx+PHP的运行模式不同,WorkerMan是基于PHP命令行 PHP CLI 运行的,使用的是不同的PHP可执行程序,使用的php.ini文件也可能不同。所以在网页中打印phpinfo()看到安装了某个扩展,不代表命令行的PHP CLI也安装了对应的扩展。

如何确定PHP CLI安装了哪些扩展

运行 php -m 会列出命令行 PHP CLI 已经安装的扩展,结果类似如下:

~# php -m
[PHP Modules]
libevent
posix
pcntl
...

如何确定PHP CLI 的php.ini文件的位置

当我们安装扩展时,可能需要手动配置php.ini文件,把扩展加进去,所以要确认PHP CLI的php.ini文件的位置。可以运行php --ini查找PHP CLI的ini文件位置,结果类似如下(各个系统显示结果会有差异):

~# php --ini
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:         /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /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-cache search memcached php
php-apc - APC (Alternative PHP Cache) module for PHP 5
php5-memcached - memcached module for php5

2、使用apt-get install安装扩展包

~# apt-get install -y php5-memcached
Reading package lists... Done
Reading state information... Done
...

centos等系统yum安装PHP扩展方法

1、利用yum search查找扩展包

~# yum search memcached php
php-pecl-memcached - memcached module for php5

2、使用yum install安装扩展包

~# yum install -y php-pecl-memcached
Reading package lists... Done
Reading state information... Done
...

说明:

使用apt或者yum安装PHP扩展会自动配置php.ini文件,安装完直接可用,十分方便。缺点是有些扩展在apt或者yum中没有对应的扩展安装包。

方法二、使用pecl安装

使用pecl install命令安装扩展

1、pecl install安装

~# pecl install memcached
downloading memcached-2.2.0.tgz ...
Starting to download memcached-2.2.0.tgz (70,449 bytes)
....

方法三、使用phpzip安装模块

一、环境介绍

[root@ghzz ~]# cat /etc/redhat-release 
CentOS release 6.5 (Final)
You have new mail in /var/spool/mail/root
[root@ghzz ~]# php -v
Zend Guard Loader requires Zend Engine API version 220121212.
The Zend Engine API version 220131226 which is installed, is newer.
Contact Zend Technologies at http://www.zend.com/ for a later version of Zend Guard Loader.
PHP 5.6.14 (cli) (built: Jul  7 2016 12:43:11) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

二、查找模块

方法一:去php安装路径下ext目录下都是模块

cd /root/software/php-5.6.14/ext/exif

如果找不到 find ./ -type d -name "php*" 去查找

###这个模块,应该是php安装包内自带的,但是./configure编译安装的时候没有加载的包

方法二:php官网 

PHP官网地址:http://pecl.php.net/packages.php


三、编译安装 (加载模块)

1)进入php存储模块目录

[root@ghzz lsolesen-pel-56d1b7f]# cd /root/software/php-5.6.14/ext/exif  ##测试环境
##如果找不到 find ./ -type f -name "php-*" 去查找
[root@ghzz exif]# ll
总用量 196
-rw-r--r-- 1 1000 1000    333 9月  30 2015 config.m4
-rw-r--r-- 1 1000 1000    308 9月  30 2015 config.w32
-rw-r--r-- 1 1000 1000     36 9月  30 2015 CREDITS
-rw-r--r-- 1 1000 1000    496 9月  30 2015 example.php
-rw-r--r-- 1 1000 1000 145331 9月  30 2015 exif.c
-rw-r--r-- 1 1000 1000   4933 9月  30 2015 exif.dsp
-rw-r--r-- 1 1000 1000   1953 9月  30 2015 package.xml
-rw-r--r-- 1 1000 1000   1463 9月  30 2015 php_exif.h
-rw-r--r-- 1 1000 1000     29 9月  30 2015 test.php
drwxr-xr-x 2 1000 1000   4096 9月  30 2015 tests
-rw-r--r-- 1 1000 1000  11232 9月  30 2015 test.txt

2)使用phpize添加php动态模块

作用:使用phpize生成

[root@ghzz exif]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
[root@ghzz exif]# ./configure -with-php-config=/usr/local/php/bin/php-config
checking for grep that handles long lines and -e... /bin/grep
#。。。省略若干字段
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@ghzz exif]# make && make install
/bin/sh /root/software/php-5.6.14/ext/exif/libtool --mode=compile cc  -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 -o exif.lo 
mkdir .libs
 cc -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=link cc -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   -o exif.la -export-dynamic -avoid-version -prefer-pic -module -rpath /root/software/php-5.6.14/ext/exif/modules  exif.lo 
cc -shared  .libs/exif.o   -Wl,-soname -Wl,exif.so -o .libs/exif.so
creating exif.la
(cd .libs && rm -f exif.la && ln -s ../exif.la exif.la)
/bin/sh /root/software/php-5.6.14/ext/exif/libtool --mode=install cp ./exif.la /root/software/php-5.6.14/ext/exif/modules
cp ./.libs/exif.so /root/software/php-5.6.14/ext/exif/modules/exif.so
cp ./.libs/exif.lai /root/software/php-5.6.14/ext/exif/modules/exif.la
PATH="$PATH:/sbin" ldconfig -n /root/software/php-5.6.14/ext/exif/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /root/software/php-5.6.14/ext/exif/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
[root@ghzz exif]# vi /usr/local/php/etc/php.ini
##如果文件路径不存在,就去安装目录查找php.ini文件
查找:extension = 再最后一个extension= 后面添加上extension = “exif.so”
[root@ghzz ext]# grep -n  "exif.so" /usr/local/php/etc/php.ini 
743:extension = "exif.so"
[root@ghzz exif]# /etc/init.d/php-fpm restart   ##重启加载php模块

四、此时可能出现模块加载报错

Gracefully shutting down php-fpm . done
Starting php-fpm [06-Jan-2017 13:43:43] NOTICE: PHP message: PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) ‘fileinfo.so’ in Unknown on line 0
重新执行上面的操作还是一直报这个错误

解决方法

 到你的模块安装目录,我这里是:

cd  /****/soft/lnmp1.2-full/src/php-5.6.14/ext/exif
make clean

在重新执行上面的全部命令,安装就成功了

报错原因:

因为之前编译的库文件.so存在异常,所以没有将新的写入,有冲突,需要清空后重新编译,即可启动

五、检查模块运行情况及效果

[root@ghzz ext]# php -m|grep exif
exif


相关内容

热门资讯

好用的云手机,桃心云手机双系统... 玩手游、搞副业的朋友,大概率都有过同一个烦恼——手里的实体手机不够用。我这话不是凭空说的,是自己亲身...
清华大学教授吴华强称华为韬定律... 5 月 27 日消息,在 5 月 25 日召开的 2026 国际电路与系统研讨会上,。这是中国企业在...
2026年生物多样性保护和可持... 河南日报讯 (全媒体记者 吴倩 李世杰 通讯员 赵亚虹 史娆)5月22日是第26个国际生物多样性日。...
文润天山 豫疆同辉丨豫疆万里情 “辕门外三声炮如同雷震……”在新疆哈密市豫哈第三实验学校的教室里,稚嫩而清脆的童声每周都会准时响起。...
“日方想让中美俄都同意,难” 【文/观察者网 王一】联合国围绕《不扩散核武器条约》(NPT)未来走向的最新一轮审议会议日前无果而终...
国网河南电力牵头立项发布无人机... 如何让智慧城市、智慧社区中的能源管理系统安全规范运行?怎样更好保障无人机在智慧城市中规模化、智能化充...
130万条业主信息被倒卖 警方... 【大河财立方消息】公安部网安局5月27日消息,近日,四川成都网安部门重拳出击,成功破获一起特大侵犯公...
黄河科技学院参加第64届中国高... 5月22-24日,由中国高等教育学会主办的第64届中国高等教育博览会在南昌绿地国际博览中心举行。黄河...
千里姻缘“衣”线牵 安阳市北关区柏庄镇一家服装加工企业内,工人正在赶制服装订单。 张瞾 摄5月8日,浙江省湖州市吴兴区织...
拜登起诉美司法部 据彭博社、美国广播公司(ABC)等媒体报道,美国前总统拜登当地时间26日起诉美国司法部,以阻止官员们...