php俩种方式安装redis扩展
方法一:phpize命令安装,需要先下载安装包
一,Linux(centos)系统php5.X:
1,下载编译。
下载:https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz到/usr/local/src目录
cd /usr/local/src #进入软件包存放目录
tar zxvf phpredis-2.2.4.tar.gz #解压
cd phpredis-2.2.4 #进入安装目录
安装扩展:
,这时候会在extension目录下生成相应的configure文件
/usr/local/php/bin/phpize
./configure --with-php-config=/alidata/server/php/bin/php-config
make
make install
安装完成之后,出现下面的安装路径
/alidata/server/php/lib/php/extensions/no-debug-non-zts-20121212/
2、配置php支持redis扩展。
vi /usr/local/php/etc/php.ini #编辑配置文件,在最后一行添加以下内容
extension="/alidata/server/php/lib/php/extensions/no-debug-non-zts-20121212/redis.so"
3 重启php观察效果:
查看php进程的pid ps -ef |grep php-fpm |grep master
通过kill -USR2重新启动php-fpm
INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块
ps -ef |grep php-fpm |grep master | awk '{print $2}' | xargs kill -USR2
4 验证
在网页根目录编写一个test.php文件,并在网页中查看,
<?php
phpinfo()
?>
如果你没有重启php-fpm的进程,最好不要通过命令去查看,可能会导致你觉得你的redis扩展已经加载到配置中
php -m 或者 php -i |grep redis
二,Linux(centos)系统php7.X
下载地址: https://github.com/phpredis/phpredis/archive/php7.zip
复制到/usr/local目录下解压:unzip phpredis-php7.zip
然后进入解压后的文件的目录,开始重新编译phpize:
cd phpredis-php7
/usr/local/php/bin/phpize
./configure --with-php-config=/alidata/server/php/bin/php-config
make && make instal
注意:php-config需根据自己的编译环境确定路径。
最后在php.ini里面加入:extension=redis.so 或者加入绝对路径。
重启php-fpm或者重启apache之类的服务,通过phpinfo查看。
方法二:使用yum命令安装
如果PHP是通过yum命令安装的,则扩展也可以通过yum安装
依次执行以下三步,中间要求输入内容的都执行“回车”:
1、命令行运行yum install libevent-devel
2、命令行运行pecl install channel://pecl.php.net/libevent-0.1.0
3、命令行运行echo extension=libevent.so > /etc/php.d/libevent.ini
以上步骤中,需要安装pecl,如果没有,以下为安装方法:
//打开对应安装版本目录
cd /usr/local/php/bin/
//curl下载
curl -o go-pear.php http://pear.php.net/go-pear.phar
//安装
php go-pear.php
方式三 pecl ,这安装的是其他模块,思路一样
环境 :centos7
脚本安装php5.6 主要是直接yum安装的比较方便,随后需要添加新的模块
#!/bin/bash
set -x
#yum安装LNMP环境,可区分centos6、7
#SOFTDIR="/tmp/softwares"
#[ -d $SOFTDIR ] || mkdir -p $SOFTDIR
function install_php() {
if [ "$(uname -r | grep 2.6 | wc -l)" = "1" ]; then
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
else
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
fi
yum clean all && yum install -y php56w php56w-opcache && yum install -y --skip-broken php56w*
[ "$?" != "0" ] && echo "install php56w* failed" && exit 1
}
function configure_php() {
#安装yaf
cd $SOFTDIR
wget -c http://pecl.php.net/get/yaf-2.3.3.tgz && tar -zxf yaf-2.3.3.tgz && cd yaf-2.3.3 && phpize
./configure --with-php-config=/usr/bin/php-config && make && make install
cat >> /etc/php.ini <<'EOF'
[yaf]
yaf.environ = product
yaf.library = NULL
yaf.cache_config = 0
yaf.name_suffix = 1
yaf.name_separator = ""
yaf.forward_limit = 5
yaf.use_namespace = 1
yaf.use_spl_autoload = 0
extension=yaf.so
EOF
#安装msgpack yar
yes | pecl install channel://pecl.php.net/msgpack-0.5.7
sed -i '/extension_dir = "ext"/a\extension=msgpack.so' /etc/php.ini
yes | pecl install yar
if [ "$?" != "0" ];then
wget -c http://pecl.php.net/get/yar-1.2.5.tgz && tar -zxf yar-1.2.5.tgz && cd yar-1.2.5 && phpize
./configure --with-php-config=/usr/bin/php-config && make && make install
fi
sed -i '/extension=msgpack.so/a\extension=yar.so' /etc/php.ini
#配置php.ini 和 php-fpm
mv /etc/php.d/json.ini /etc/php.d/json.ini.bak
sed -i '/extension_dir = "ext"/a\extension=json.so' /etc/php.ini
sed -i 's/^upload_max_filesize.*/upload_max_filesize = 10M/' /etc/php.ini
sed -i 's/listen = 127.0.0.1:9000/listen=\/dev\/shm\/php-fpm.sock/' /etc/php-fpm.d/www.conf
sed -i 's/user = apache/user = www/' /etc/php-fpm.d/www.conf
sed -i 's/group = apache/group = www/' /etc/php-fpm.d/www.conf
sed -i 's/;listen.owner = nobody/listen.owner = www/' /etc/php-fpm.d/www.conf
sed -i 's/;listen.group = nobody/listen.group = www/' /etc/php-fpm.d/www.conf
sed -i 's/pm.max_children = 50/pm.max_children = 300/' /etc/php-fpm.d/www.conf
sed -i 's#;pm.status_path.*#pm.status_path = /xingka_status#' /etc/php-fpm.d/www.conf
sed -i 's/^;listen.backlog = -1/listen.backlog = 1024/' /etc/php-fpm.d/www.conf
chown -R www.www /var/lib/php/session
chmod -R 777 /var/lib/php/session
}
function youhua_php() {
#php参数优化
phpfpmconf=/etc/php-fpm.d/www.conf
Mem=`free -m | awk '/Mem:/{print $2}'`
sed -i "s@^pm.max_children.*@pm.max_children = $(($Mem/2/20))@" $phpfpmconf
sed -i "s@^pm.start_servers.*@pm.start_servers = $(($Mem/2/30))@" $phpfpmconf
sed -i "s@^pm.min_spare_servers.*@pm.min_spare_servers = $(($Mem/2/40))@" $phpfpmconf
sed -i "s@^pm.max_spare_servers.*@pm.max_spare_servers = $(($Mem/2/20))@" $phpfpmconf
}
function postwork() {
systemctl start php-fpm && systemctl enable php-fpm
}
install_php
configure_php
youhua_php
postwork
echo -e "End.\n****************************Thanks!********************************"
如何添加新模块呢
pecl install imagick
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading imagick-3.7.0.tgz ...
Starting to download imagick-3.7.0.tgz (360,138 bytes)
.........................................................................done: 360,138 bytes
33 source files, building
running: phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
Please provide the prefix of ImageMagick installation [autodetect] : #直接回车即可
cat > /etc/php.d/imagick.ini << EOF
;Enable imagick extension module
extension=imagick.so
EOF
cat > /etc/php-zts.d/imagick.ini << EOF
;Enable imagick extension module
extension=imagick.so
EOF
systemctl restart php-fpm
更多推荐
所有评论(0)