PHP扩展模块安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP扩展模块安装相关的知识,希望对你有一定的参考价值。

php扩展模块安装

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


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

[[email protected] ~]# /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扩展模块。

[[email protected] ~]# cd /usr/local/src/

[[email protected] src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop 

[[email protected] src]# mv develop phpredis-develop.zip

[[email protected] src]# unzip phpredis-develop.zip  //yum install -y unzip

[[email protected] src]# cd phpredis-develop

[[email protected] phpredis-develop]# 

[[email protected] src]# cd phpredis-develop

[[email protected] 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.

[[email protected] phpredis-develop]# yum install -y autoconf

[[email protected] phpredis-develop]# /usr/local/php7/bin/phpize

Configuring for:

PHP Api Version:         20160303

Zend Module Api No:      20160303

Zend Extension Api No:   320160303

[[email protected] 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

[[email protected] phpredis-develop]# ./configure --with-php-config=/usr/local/php7/bin/php-config

[[email protected] phpredis-develop]# echo $?

0

[[email protected] phpredis-develop]# make

[[email protected] phpredis-develop]# echo $?

0

[[email protected] phpredis-develop]# make install

Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/

[[email protected] phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/

opcache.so  redis.so

[[email protected] 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]

[[email protected] phpredis-develop]# /usr/local/php7/bin/php -m |grep redis

[[email protected] 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

[[email protected] phpredis-develop]# vim /usr/local/php7/etc/php.ini  //增加一行配置(可以放到文件最后一行)


定义如下:

extension = redis.so


[[email protected] phpredis-develop]# /usr/local/php7/bin/php -m |grep redis

redis


增加示例图:

技术分享图片


报错:

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

技术分享图片


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

技术分享图片



举例:

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


[[email protected] ~]# cd /usr/local/src/php-7.1.6

[[email protected] 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

[[email protected] php-7.1.6]# cd ext/

[[email protected] 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

[[email protected] ext]# /usr/local/php7/bin/php -m |grep zip

[[email protected] ext]# cd zip/

[[email protected] zip]# ls

config.m4  config.w32  CREDITS  examples  lib  LICENSE_libzip  php_zip.c  php_zip.h  tests  TODO  zip_stream.c

[[email protected] zip]# /usr/local/php7/bin/phpize

Configuring for:

PHP Api Version:         20160303

Zend Module Api No:      20160303

Zend Extension Api No:   320160303

[[email protected] zip]# ./configure --with-php-config=/usr/local/php7/bin/php-config

[[email protected] zip]# make

[[email protected] zip]# echo $?

0

[[email protected] zip]# make install

Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/

[[email protected] zip]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/

opcache.so  redis.so  zip.so


以上是关于PHP扩展模块安装的主要内容,如果未能解决你的问题,请参考以下文章

PHP 如何安装扩展模块

PHP动态扩展模块安装

88.PHP扩展模块安装

php扩展模块安装

四十PHP扩展模块安装

PHP扩展模块的安装