阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux安装PHP扩展模块详解

213次阅读
没有评论

共计 5964 个字符,预计需要花费 15 分钟才能阅读完成。

PHP 扩展模块安装

编译 httpd 时,有涉及动态和静态模块,PHP 也一样有静态与动态之分,之前所涉及到的 PHP 安装都全部为静态,并没有任何动态的模块,所谓动态,就是一个独立存在的.so 文件,在 httpd 中 PHP 就是以动态模块的形式被加载的。PHP 一旦编译完成后,要想再增加一个功能的话,要么重新编译 PHP,要么直接编译一个扩展模块(生成一个.so 文件),然后在 php.ini 中配置一下,就可以被加载使用了。

1. 查看 PHP 加载了哪些模块

[root@linuxmi ~]# /usr/local/php/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
ereg
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

2. 安装一个 PHP 的 redis 扩展模块。

[root@linuxmi ~]# cd /usr/local/src/
[root@linuxmi src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop 
[root@linuxmi src]# mv develop phpredis-develop.zip
[root@linuxmi src]# unzip phpredis-develop.zip  //yum install -y unzip
[root@linuxmi src]# cd phpredis-develop
[root@linuxmi phpredis-develop]# 
[root@linuxmi src]# cd phpredis-develop
[root@linuxmi phpredis-develop]# /usr/local/php7/bin/phpize // 生成 configure 文件 
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
[root@linuxmi phpredis-develop]# yum install -y autoconf
[root@linuxmi phpredis-develop]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303
[root@linuxmi phpredis-develop]# ls
acinclude.m4       cluster_library.h  config.sub    CREDITS            library.c         mkdeb.sh         redis_array.h       redis_commands.c  serialize.list
aclocal.m4         cluster.markdown   configure     debian             library.h         mkinstalldirs    redis_array_impl.c  redis_commands.h  tests
arrays.markdown    common.h           configure.in  debian.control     ltmain.sh         package.xml      redis_array_impl.h  redis_session.c
autom4te.cache     config.guess       config.w32    install-sh         Makefile.global   php_redis.h      redis.c             redis_session.h
build              config.h.in        COPYING       ISSUE_TEMPLATE.md  missing           README.markdown  redis_cluster.c     rpm
cluster_library.c  config.m4          crc16.h       liblzf             mkdeb-apache2.sh  redis_array.c    redis_cluster.h     run-tests.php
[root@linuxmi phpredis-develop]# ./configure --with-php-config=/usr/local/php7/bin/php-config
[root@linuxmi phpredis-develop]# echo $?
0
[root@linuxmi phpredis-develop]# make
[root@linuxmi phpredis-develop]# echo $?
0
[root@linuxmi phpredis-develop]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
[root@linuxmi phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
opcache.so  redis.so
[root@linuxmi phpredis-develop]# /usr/local/php7/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]
[root@linuxmi phpredis-develop]# /usr/local/php7/bin/php -m |grep redis
[root@linuxmi phpredis-develop]# /usr/local/php/bin/php -i |grep extension_dir  // 查看扩展模块存放目录,我们可以在 php.ini 中去自定义该路径 
PHP Warning:  Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0
extension_dir => /usr/local/php/lib/php/extensions/no-debug-zts-20131226 => /usr/local/php/lib/php/extensions/no-debug-zts-20131226
sqlite3.extension_dir => no value => no value
[root@linuxmi phpredis-develop]# vim /usr/local/php7/etc/php.ini  // 增加一行配置(可以放到文件最后一行)定义如下:extension = redis.so

[root@linuxmi phpredis-develop]# /usr/local/php7/bin/php -m |grep redis
redis
增加示例图:

Linux 安装 PHP 扩展模块详解

报错:

缺少 autoconf 包,安装 yum install -y autoconf

Linux 安装 PHP 扩展模块详解

这个不影响使用,如果要去掉它,可以在 php.ini 里设置一下 timezone 那个参数

Linux 安装 PHP 扩展模块详解

举例:

你想编译一个扩展模块的时候,如果它自带的源码包 ext 下有这个目录,那就可以直接在目录下编译它,如果没有那就需要去官网下载,下面是给大家举例一个 zip 模块实验操作如下:

[root@linuxmi ~]# cd /usr/local/src/php-7.1.6
[root@linuxmi php-7.1.6]# ls
acinclude.m4      configure        install-sh          Makefile.global   php.gif                       README.RELEASE_PROCESS            server-tests.php
aclocal.m4        configure.in     libphp7.la          Makefile.objects  php.ini-development           README.SELF-CONTAINED-EXTENSIONS  snapshot
appveyor          CONTRIBUTING.md  libs                makerpm           php.ini-production            README.STREAMS                    stamp-h.in
build             CREDITS          libtool             meta_ccld         README.EXT_SKEL               README.SUBMITTING_PATCH           stub.c
buildconf         ext              LICENSE             missing           README.GIT-RULES              README.TESTING                    tests
buildconf.bat     EXTENSIONS       ltmain.sh           mkinstalldirs     README.input_filter           README.TESTING2                   travis
CODING_STANDARDS  footer           main                modules           README.MAILINGLIST_RULES      README.UNIX-BUILD-SYSTEM          TSRM
config.guess      generated_lists  makedist            netware           README.md                     README.WIN32-BUILD-SYSTEM         UPGRADING
config.log        genfiles         Makefile            NEWS              README.namespaces             run-tests.php                     UPGRADING.INTERNALS
config.nice       header           Makefile.frag       pear              README.NEW-OUTPUT-API         sapi                              vcsclean
config.status     include          Makefile.fragments  php7.spec         README.PARAMETER_PARSING_API  scripts                           win32
config.sub        INSTALL          Makefile.gcov       php7.spec.in      README.REDIST.BINS            server-tests-config.php           Zend
[root@linuxmi php-7.1.6]# cd ext/
[root@linuxmi ext]# ls
bcmath      date      ext_skel_win32.php  gmp        json      mysqlnd  pcre          pdo_odbc    pspell      simplexml  sqlite3   tokenizer  xsl
bz2         dba       fileinfo            hash       ldap      oci8     pdo           pdo_pgsql   readline    skeleton   standard  wddx       zip
calendar    dom       filter              iconv      libxml    odbc     pdo_dblib     pdo_sqlite  recode      snmp       sysvmsg   xml        zlib
com_dotnet  enchant   ftp                 imap       mbstring  opcache  pdo_firebird  pgsql       reflection  soap       sysvsem   xmlreader
ctype       exif      gd                  interbase  mcrypt    openssl  pdo_mysql     phar        session     sockets    sysvshm   xmlrpc
curl        ext_skel  gettext             intl       mysqli    pcntl    pdo_oci       posix       shmop       spl        tidy      xmlwriter
[root@linuxmi ext]# /usr/local/php7/bin/php -m |grep zip
[root@linuxmi ext]# cd zip/
[root@linuxmi zip]# ls
config.m4  config.w32  CREDITS  examples  lib  LICENSE_libzip  php_zip.c  php_zip.h  tests  TODO  zip_stream.c
[root@linuxmi zip]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303
[root@linuxmi zip]# ./configure --with-php-config=/usr/local/php7/bin/php-config
[root@linuxmi zip]# make
[root@linuxmi zip]# echo $?
0
[root@linuxmi zip]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
[root@linuxmi zip]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
opcache.so  redis.so  zip.so

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2018-01/150006.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计5964字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中