Press "Enter" to skip to content

PHP安装扩展模块

例如安装memcache模块:
前提:PHP已安装
主机环境:
[root@test modules]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
具体步骤:
查看当前已安装了哪些模块:
[root@test modules]# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
ereg
exif
fileinfo
filter
ftp
gettext
gmp
hash
iconv
json
libxml
mhash
openssl
pcntl
pcre
Phar
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
standard
tokenizer
xml
zip
zlib

[Zend Modules]
由上可见memcache模块未安装.

[root@test ~]# wget http://pecl.php.net/get/memcache-3.0.8.tgz
[root@test ~]# tar -zxvf memcache-3.0.8.tgz
[root@test ~]# cd memcache-3.0.8
[root@test memcache-3.0.8]# /usr/bin/phpize //可which phpize查看phpize具体路径
Can't find PHP headers in /usr/include/php
发现有报错,需安装php-devel.
[root@test memcache-3.0.8]# yum install php-devel -y
[root@test memcache-3.0.8]# /usr/bin/phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
[root@test memcache-3.0.8]# ./configure --with-php-config=/usr/bin/php-config //php-config路径可用locate php-config查找,查找前需先执行/usr/bin/phpize
发现有报错:checking for the location of zlib... configure: error: memcache support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located
需安装zlib-devel.
[root@test memcache-3.0.8]# yum install -y zlib-devel
再次编译:
[root@test memcache-3.0.8]# ./configure --with-php-config=/usr/bin/php-config
没报错的话说明编译成功.
[root@test memcache-3.0.8]# make && make install
.
.
.(中间省略若干行,主要看下面几行)
----------------------------------------------------------------------

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

Installing shared extensions: /usr/lib64/php/modules/
上面说明安装成功,并且加载的模块路径为:/usr/lib64/php/modules/

[root@test modules]# cd /usr/lib64/php/modules/
[root@test modules]# ll
total 3628
-rwxr-xr-x 1 root root 74776 Apr 13 03:04 curl.so
-rwxr-xr-x 1 root root 2713464 Apr 13 03:04 fileinfo.so
-rwxr-xr-x 1 root root 44784 Apr 13 03:04 json.so
-rwxr-xr-x 1 root root 504368 May 14 16:23 memcache.so
-rw-rw-r-- 1 500 500 28745 Apr 8 2013 package.xml
-rwxr-xr-x 1 root root 272112 Apr 13 03:04 phar.so
-rwxr-xr-x 1 root root 58496 Apr 13 03:04 zip.so
修改php配置文件,修改extension_dir路径:
[root@test memcache-3.0.8]# vi /etc/php.ini //可以locate php.ini查找配置文件路径
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
extension_dir = "/usr/lib64/php/modules/" //修改此处,路径就是上面make install以后得到的路径
; On windows:
; extension_dir = "ext"
在php配置文件适当地方增加memcache.so:
[root@test memcache-3.0.8]# vi /etc/php.ini
[intl]
;intl.default_locale =
; This directive allows you to produce PHP errors when some error
; happens within intl functions. The value is the level of the error produced.
; Default is 0, which does not produce any errors.
;intl.error_level = E_WARNING

extension = memcache.so //增加此行,我是在sqlite模块上方加的

[sqlite]
; http://php.net/sqlite.assoc-case
;sqlite.assoc_case = 0

最后测试模块是否安装成功:
[root@test memcache-3.0.8]# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
ereg
exif
fileinfo
filter
ftp
gettext
gmp
hash
iconv
json
libxml
memcache //这个是新增的
mhash
openssl
pcntl
pcre
Phar
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
standard
tokenizer
xml
zip
zlib

[Zend Modules]
由上可见新增了memcache模块,说明安装成功.

如果需要安装的模块在/your/path/php/ext下面有,进入相关路径直接从/usr/bin/phpize这一步开始即可.

Be First to Comment

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注