php安装redis扩展
这篇文章主要介绍了PHP安装扩展 ,有着一定的参考价值,一般php安装目录中都有许多扩展组件的安装包,可以先看看php源码包是否有自己需要的扩展,现在分享给大家,有需要的朋友可以参考一下,
一、php扩展管理
1.什么是php扩展
php扩展就是php核心并不支持的功能,然后可以通过扩展的方式进行扩展PHP的功能,常见的扩展如MySQL,gb2等等。
2.查看php安装了那些扩展
方法一:通过phpinfo()函数,进行查看,红框的都是php的扩展
方法二:执行php -m 命令:
方法三:使用php的get_loaded_extensions()函数
1 2 3 |
|
以上例程的输出类似于:
Array( [0] => xml [1] => wddx [2] => standard [3] => session [4] => posix [5] => pgsql [6] => pcre [7] => gd [8] => ftp [9] => db [10] => calendar [11] => bcmath)
方法四:extension_loaded函数检查一个扩展是否已经加载,如果 name 指定的扩展已加载,返回TRUE,否则返回 FALSE。
1 2 3 4 5 6 7 |
|
3.管理php扩展
a.设定扩展所在目录,将php.ini的extension_dir设定成自己php扩展路径
b.加载扩展
二、windows安装php扩展
1.下载
http://pecl.php.net/是官方的扩展库,我们可以在这里下载自想要的扩展
2.选择版本
已安装redis为例:
点击
安装windows的php扩展需要注意版本的选择:php的版本、是否是线性安全、操作系统的位数。
3.安装
将下载好的压缩包解压,然后把里面的php_redis.dll放到php.ini中制定的文件夹里面,并把redis模块加载,然后从起服务器。
三、linux安装php扩展
1.yum或者apt-get安装
2.使用pecl安装
1)、pecl install安装
~# pecl install memcached
downloading memcached-2.2.0.tgz ...
Starting to download memcached-2.2.0.tgz (70,449 bytes)....
2)、配置php.ini
通过运行 php --ini查找php.ini文件位置,然后在文件中添加extension=memcached.so
3.phpize安装——以redis为例
1)、下载php扩展包
[root@localhost ~]# wgethttp://download.redis.io/releases/redis-5.0.2.tar.gz
2)、解压缩并进入扩展包目录
[root@localhost ~]# tar -xzvvfredis-5.0.2.tgz
[root@localhostredis-5.0.2]# cd redis-5.0.2
3)、执行phpize
[root@localhostredis-5.0.2]# phpize
4)、执行 ./configure
[root@localhostredis-5.0.2]# ./configure --with-php-config=/usr/bin/php-config #--with-php-config=/usr/bin/php-config 这个php-config即安装php的目录里的脚本
5)、make && make install
[root@localhostredis-5.0.2]# make && make install #编译且编辑安装 完成之后 会生成扩展文件的目录
6)、配置php.ini
extension=redis.so #在扩展里面添加,之后重启php即可 service /usr/local/php/sbin/php-fpm restart
4.直接安装(类似windows)
直接下载将下载好的压缩包,解压后将.so后缀的文件直接放到指定的路径,然后配置php.ini文件。
本文转自,有小小修改:http://www.php.cn/php-weizijiaocheng-392756.html
其他的php扩展也是同样的安装方式,可以举一反三,这里就不多说。下面再介绍 redis 在centos 7 中自启;
下面是命令的操作方式:
[root@localhost ~]# cd redis-5.0.2 [root@localhost redis-5.0.]# cd utils/ [root@localhost utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] 9207 Please select the redis config file name [/etc/redis/9207.conf] /usr/local/redis5/conf/redis_9207.conf Please select the redis log file name [/var/log/redis_9207.log] /usr/local/redis5/logs/reids_9207.log Please select the data directory for this instance [/var/lib/redis/9207] /usr/local/redis5/datas/9207 Please select the redis executable path [] /usr/local/redis5/bin/redis-server Selected config: Port : 9207 Config file : /usr/local/redis5/conf/redis_9207.conf Log file : /usr/local/redis5/logs/reids_9207.log Data dir : /usr/local/redis5/datas/9207 Executable : /usr/local/redis5/bin/redis-server Cli Executable : /usr/local/redis5/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort.^C [root@localhost utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] 9207 Please select the redis config file name [/etc/redis/9207.conf] /usr/local/redis5/conf/redis_9207.conf Please select the redis log file name [/var/log/redis_9207.log] /usr/local/redis5/logs/reids_9207.log Please select the data directory for this instance [/var/lib/redis/9207] /usr/local/redis5/datas/9207 Please select the redis executable path [] /usr/local/redis5/bin/redis-server Selected config: Port : 9207 Config file : /usr/local/redis5/conf/redis_9207.conf Log file : /usr/local/redis5/logs/reids_9207.log Data dir : /usr/local/redis5/datas/9207 Executable : /usr/local/redis5/bin/redis-server Cli Executable : /usr/local/redis5/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/9207.conf => /etc/init.d/redis_9207 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! /var/run/redis_9207.pid exists, process is already running or crashed Installation successful!
分别讲解一下,几个关键的命令:
./install_server.sh
上面是执行安装服务脚本程序,类似windows下的exe文件
Please select the redis port for this instance: [6379] 9207
上面是让你填写redis的启动端口,默认是6379
Please select the redis config file name [/etc/redis/9207.conf] /usr/local/redis5/conf/redis_9207.conf
上面是让你填写启动redis时读取的配置文件
Please select the redis log file name [/var/log/redis_9207.log] /usr/local/redis5/logs/reids_9207.log
上面是redis的日志文件
Please select the data directory for this instance [/var/lib/redis/9207] /usr/local/redis5/datas/9207
上面是redis的数据目录
Please select the redis executable path [] /usr/local/redis5/bin/redis-server
上面是指定redis服务启动的脚本文件目录
这样就完成了centos7下redis自动启动的配置
Dcr163的博客
http://dcr163.cn/197.html(转载时请注明本文出处及文章链接)