配置Lnmp+redis

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了配置Lnmp+redis相关的知识,希望对你有一定的参考价值。

配置Lnmp+redis

[[email protected] ~]# yum -y install gcc gcc-c++ pcre-devel zlib-devel

[[email protected] lnmp]# tar -xf nginx-1.12.2.tar.gz

[[email protected] lnmp]# cd nginx-1.12.2/

[[email protected] nginx-1.12.2]# ./configure

[[email protected] nginx-1.12.2]# make && make install

[[email protected] nginx-1.12.2]# ln -s /usr/local/nginx/sbin/* /sbin/

[[email protected] nginx-1.12.2]# nginx

[[email protected] nginx-1.12.2]# ss -antulp | grep nginx

Tcp LISTEN 0 128 :80 :* users (("nginx",pid=8346,fd=6),("nginx",pid=8345,fd=6))

[[email protected] nginx-1.12.2]# yum -y install php-common

[[email protected] lnmp]# rpm -ivh php-fpm-5.4.16-42.el7.x86_64.rpm

[[email protected] lnmp]# systemctl start php-fpm

[[email protected] lnmp]# systemctl enable php-fpm

[[email protected] lnmp]# vim /usr/local/nginx/conf/nginx.conf

65 location ~ .php$ {

66 root html;

67 fastcgi_pass 127.0.0.1:9000;

68 fastcgi_index index.php;

69 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

70 include fastcgi.conf;

71 }

[[email protected] lnmp]# nginx -s reload

[[email protected] lnmp]# ss -antulp | grep nginx

tcp LISTEN 0 128 :80 :* users:(("nginx",pid=8646,fd=6),("nginx",pid=8345,fd=6))

[[email protected] lnmp]# vim /usr/local/nginx/html/index.php

<?php

phpinfo();

?>

[[email protected] redis]# yum -y install autoconf automake

[[email protected] redis]# yum -y install php-devel-5.4.16-42.el7.x86_64.rpm

[[email protected] redis]# tar -xf php-redis-2.2.4.tar.gz

[[email protected] redis]# cd phpredis-2.2.4/

[[email protected] phpredis-2.2.4]# phpize

Configuring for:

PHP Api Version: 20100412

Zend Module Api No: 20100425

Zend Extension Api No: 220100425

[[email protected] phpredis-2.2.4]# ll /usr/bin/php-config

-rwxr-xr-x. 1 root root 4424 11月 6 2016 /usr/bin/php-config

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

[[email protected] phpredis-2.2.4]# make && make install

...

....

Build complete.

Don‘t forget to run ‘make test‘. 安装到此会出现如下报错

解决办法:

1.make install 查看路径

Installing shared extensions: /usr/lib64/php/modules/

[[email protected] phpredis-2.2.4]# ls /usr/lib64/php/modules/

curl.so fileinfo.so json.so phar.so redis.so zip.so

2.更改php配置文件

[[email protected] phpredis-2.2.4]# vim /etc/php.ini

728 extension_dir = "/usr/lib64/php/modules/"

729 ; On windows:

730 extension_dir = "redis.so"

[[email protected] phpredis-2.2.4]# systemctl restart php-fpm

php -m | grep -i redis 查看是否支持redis

如果输入上面命令出现以下问题:

[[email protected] phpredis-2.2.4]# php -m | grep redis

PHP Warning: PHP Startup: Unable to load dynamic library ‘redis.so/curl.so‘ - redis.so/curl.so: cannot open shared object file: No such file or directory in Unknown on line 0

解决办法:

[[email protected] phpredis-2.2.4]# vim /etc/php.ini

把extension_dir = "redis.so" >> extension = "redis.so"

[[email protected] phpredis-2.2.4]# vim /usr/local/nginx/html/test1.php

<?php

$redis = new redis();

$redis->connect(‘192.168.4.40‘,6040);

$redis->set(‘redistest‘,‘666666‘);

echo $redis->get(‘redistest‘);

?>

[[email protected] phpredis-2.2.4]# redis-cli -h 192.168.4.40 -p 6040

192.168.4.40:6040> keys *

1) "redistest"

以上是关于配置Lnmp+redis的主要内容,如果未能解决你的问题,请参考以下文章

LNMP+Redis

快速配置php7 + swoole + redis

LNMP平台对接redis服务

LNMP+Redis

lnmp redis 无法外部访问 解决

Mac下docker搭建lnmp环境 + redis + elasticsearch