配置Lnmp+redis
[root@40 ~]# yum -y install gcc gcc-c++ pcre-devel zlib-devel
[root@40 lnmp]# tar -xf nginx-1.12.2.tar.gz
[root@40 lnmp]# cd nginx-1.12.2/
[root@40 nginx-1.12.2]# ./configure
[root@40 nginx-1.12.2]# make && make install
[root@40 nginx-1.12.2]# ln -s /usr/local/nginx/sbin/* /sbin/
[root@40 nginx-1.12.2]# nginx
[root@40 nginx-1.12.2]# ss -antulp | grep nginx
Tcp LISTEN 0 128 :80 :* users (("nginx",pid=8346,fd=6),("nginx",pid=8345,fd=6))
[root@40 nginx-1.12.2]# yum -y install php-common
[root@40 lnmp]# rpm -ivh php-fpm-5.4.16-42.el7.x86_64.rpm
[root@40 lnmp]# systemctl start php-fpm
[root@40 lnmp]# systemctl enable php-fpm
[root@40 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 }
[root@40 lnmp]# nginx -s reload
[root@40 lnmp]# ss -antulp | grep nginx
tcp LISTEN 0 128 :80 :* users:(("nginx",pid=8646,fd=6),("nginx",pid=8345,fd=6))
[root@40 lnmp]# vim /usr/local/nginx/html/index.php
phpinfo();
?>
[root@40 redis]# yum -y install autoconf automake
[root@40 redis]# yum -y install php-devel-5.4.16-42.el7.x86_64.rpm
[root@40 redis]# tar -xf php-redis-2.2.4.tar.gz
[root@40 redis]# cd phpredis-2.2.4/
[root@40 phpredis-2.2.4]# phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100425
Zend Extension Api No: 220100425
[root@40 phpredis-2.2.4]# ll /usr/bin/php-config
-rwxr-xr-x. 1 root root 4424 11月 6 2016 /usr/bin/php-config
[root@40 phpredis-2.2.4]# ./configure --with-php-config=/usr/bin/php-config
[root@40 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/
[root@40 phpredis-2.2.4]# ls /usr/lib64/php/modules/
curl.so fileinfo.so json.so phar.so redis.so zip.so
2.更改php配置文件
[root@40 phpredis-2.2.4]# vim /etc/php.ini
728 extension_dir = "/usr/lib64/php/modules/"
729 ; On windows:
730 extension_dir = "redis.so"
[root@40 phpredis-2.2.4]# systemctl restart php-fpm
php -m | grep -i redis 查看是否支持redis
如果输入上面命令出现以下问题:
[root@43 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
解决办法:
[root@43 phpredis-2.2.4]# vim /etc/php.ini
把extension_dir = "redis.so" >> extension = "redis.so"
[root@40 phpredis-2.2.4]# vim /usr/local/nginx/html/test1.php
$redis = new redis();
$redis->connect('192.168.4.40',6040);
$redis->set('redistest','666666');
echo $redis->get('redistest');
?>
[root@40 phpredis-2.2.4]# redis-cli -h 192.168.4.40 -p 6040
192.168.4.40:6040> keys *
1) "redistest"
转载于:https://blog.51cto.com/13124606/2146979