11.32 php扩展模块安装

扩展

apache rewrite教程 

http://coffeelet.blog.163.com/blog/static/13515745320115842755199/ 

http://www.cnblogs.com/top5/archive/2009/08/12/1544098.html

apache rewrite 出现死循环 

http://ask.apelearn.com/question/1043

php错误日志级别参考 

http://ask.apelearn.com/question/6973

php开启短标签 

http://ask.apelearn.com/question/120

php.ini详解 

http://legolas.blog.51cto.com/2682485/493917

~~1.

PHP动态扩展模块(PHP源码包里ext下没有需要的模块的情况下的安装方法)

/usr/local/src/php-7.1.6/ext/

例如我们php已经安装好了,但是发现少了一个模块。但是又不能从新编译php,那么可以用下面这种方式(实际上就是编译出一个.so的文件):

/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]

下面安装一个redis的模块 在lamp架构下,通常当做一个缓存来用

cd /usr/local/src/

wget https://codeload.github.com/phpredis/phpredis/zip/develop

mv develop phpredis-develop.zip

unzip phpredis-develop.zip

cd phpredis-develop

/usr/local/php/bin/phpize 生成configure文件(此处需生成一个configure模块),注意输出是否报错

./configure --with-php-config=/usr/local/php/bin/php-config 一般只需要加--with就可以了

make && make install

/usr/local/php/bin/php -i |grep extension_dir 查看扩展模块存放目录,我们可以在php.ini中去自定义该路径,但针对这样扩展的模块,我们不用去改他的路径,默认就好

vim /usr/local/php/etc/php.ini 增加一行配置(可以放到文件最后一行)

extension=redis.so

~~2.

假如在PHP源码包里ext下有需要的模块的情况下的安装方法

(/usr/local/src/php-7.1.6/ext/)

cd /usr/local/src/php-7.1.6/ext/

cd zip cd到需要安装的这个模块目录下

/usr/local/php7/bin/phpize 直接执行,生成.configure

./configure --with-php-config=/usr/local/php7/bin/php-config

make&&make install

实例:

~~1.

[root@axinlinux-01 ~]# /usr/local/php/bin/php -m

[PHP Modules]

[root@axinlinux-01 ~]# cd /usr/local/src

[root@axinlinux-01 src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop

[root@axinlinux-01 src]# du -sh develop

236K develop

[root@axinlinux-01 src]# mv develop phpredis-develop.zip

[root@axinlinux-01 src]# unzip phpredis-develop.zip

[root@axinlinux-01 src]# cd phpredis-develop/

[root@axinlinux-01 phpredis-develop]# ls 要生成一个.configure的文件,才能编译

arrays.markdown    cluster.markdown  COPYING  debian.control     library.c         package.xml      redis_array.h       redis_cluster.c   redis_session.c  tests
Changelog.md       common.h          crc16.h  INSTALL.markdown   library.h         php_redis.h      redis_array_impl.c  redis_cluster.h   redis_session.h
cluster_library.c  config.m4         CREDITS  ISSUE_TEMPLATE.md  mkdeb-apache2.sh  README.markdown  redis_array_impl.h  redis_commands.c  rpm
cluster_library.h  config.w32        debian   liblzf             mkdeb.sh          redis_array.c    redis.c             redis_commands.h  serialize.list

[root@axinlinux-01 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 有报错(少autoconf包)

$PHP_AUTOCONF environment variable. Then, rerun this script.

[root@axinlinux-01 phpredis-develop]# yum install -y autoconf

[root@axinlinux-01 phpredis-develop]# /usr/local/php7/bin/phpize 重新生成

Configuring for:

PHP Api Version: 20160303

Zend Module Api No: 20160303

Zend Extension Api No: 320160303 这样的输出才是正常

[root@axinlinux-01 phpredis-develop]# ls 会看到configure这个文件

acinclude.m4     Changelog.md       config.guess  configure.in  debian             liblzf           missing           php_redis.h         redis_array_impl.h  redis_commands.h  serialize.list
aclocal.m4       cluster_library.c  config.h.in   config.w32    debian.control     library.c        mkdeb-apache2.sh  README.markdown     redis.c             redis_session.c   tests
arrays.markdown  cluster_library.h  config.m4     COPYING       INSTALL.markdown   library.h        mkdeb.sh          redis_array.c       redis_cluster.c     redis_session.h
autom4te.cache   cluster.markdown   config.sub    crc16.h       install-sh         ltmain.sh        mkinstalldirs     redis_array.h       redis_cluster.h     rpm
build            common.h           configure     CREDITS       ISSUE_TEMPLATE.md  Makefile.global  package.xml       redis_array_impl.c  redis_commands.c    run-tests.php

[root@axinlinux-01 phpredis-develop]# ./configure --with-php-config=/usr/local/php7/bin/php-config

[root@axinlinux-01 phpredis-develop]# echo $?

0

[root@axinlinux-01 phpredis-develop]# make

[root@axinlinux-01 phpredis-develop]# make install

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

这个路径就是我们要的.so的文件

[root@axinlinux-01 phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/

opcache.so  redis.so

[root@axinlinux-01 phpredis-develop]# /usr/local/php7/bin/php -m 并没有这个模块,说明现在php还不支持他

[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@axinlinux-01 phpredis-develop]# /usr/local/php7/bin/php -i | grep -i extension_dir 查看一下,不用改

extension_dir => /usr/local/php7/lib/php/extensions/no-debug-zts-20160303 => /usr/local/php7/lib/php/extensions/no-debug-zts-20160303
sqlite3.extension_dir => no value => no value

[root@axinlinux-01 phpredis-develop]# vim /usr/local/php7/etc/php.ini

;extension=php_pdo_odbc.dll

;extension=php_pdo_pgsql.dll

;extension=php_pdo_sqlite.dll

;extension=php_pgsql.dll

;extension=php_shmop.dll 搜索extension,在一长串extension的最下面加上extension=redis.so

[root@axinlinux-01 phpredis-develop]# /usr/local/php7/bin/php -m |grep redis

redis 这时候就有了

[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
redis
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

~~2.

[root@axinlinux-01 php7]# cd /usr/local/src/php-7.1.6/ext/

[root@axinlinux-01 ext]# ls

bcmath      curl     exif                ftp      iconv      ldap      mysqlnd  pcntl         pdo_mysql   pgsql     recode      skeleton  sqlite3   tidy       xmlrpc
bz2         date     ext_skel            gd       imap       libxml    oci8     pcre          pdo_oci     phar      reflection  snmp      standard  tokenizer  xmlwriter
calendar    dba      ext_skel_win32.php  gettext  interbase  mbstring  odbc     pdo           pdo_odbc    posix     session     soap      sysvmsg   wddx       xsl
com_dotnet  dom      fileinfo            gmp      intl       mcrypt    opcache  pdo_dblib     pdo_pgsql   pspell    shmop       sockets   sysvsem   xml        zip
ctype       enchant  filter              hash     json       mysqli    openssl  pdo_firebird  pdo_sqlite  readline  simplexml   spl       sysvshm   xmlreader  zlib

以上是php源码包里自带的可用的模块,我们需要的这里有的话,就可直接安装

[root@axinlinux-01 ext]# /usr/local/php7/bin/php -m |grep zip 假如我们编译zip

[root@axinlinux-01 ext]# cd zip 首先cd到这个zip目录下来

[root@axinlinux-01 zip]# ls

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

[root@axinlinux-01 zip]# /usr/local/php7/bin/phpize 直接执行,生成.configure

Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303

[root@axinlinux-01 zip]# ./configure --with-php-config=/usr/local/php7/bin/php-config

[root@axinlinux-01 zip]# echo $?

0

[root@axinlinux-01 zip]# make

[root@axinlinux-01 zip]# echo $?

0

[root@axinlinux-01 zip]# make install

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

[root@axinlinux-01 zip]# echo $?

0

[root@axinlinux-01 zip]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/

opcache.so  redis.so  zip.so
07-22 20:14