部署LNMP+redis

LNMP平台部署

部署lnmp环境

1)源码安装nginx和php

[root@localhost]#yum  -y  install  gcc  pcre-devel   zlib-devel  //安装依赖
[root@localhost]#tar  -zxvf  nginx-1.12.2.tar.gz  //解压
[root@localhost]#cd nginx-1.12.2  //进源码目录
[root@localhost]#./configure  //配置
[root@localhost nginx-1.12.2]# make //编译
[root@localhost nginx-1.12.2]#make  install //安装
#如果编译出错可能是安装包没装完
[root@localhost]#yum   -y  install php php-mysql php-fpm  

2)修改配置文件nginx.conf

#开启动态页面支持php
[root@localhost] # vim   +65  /usr/local/nginx/conf/nginx.conf
      location ~ \.php$ {
              root           html;
              fastcgi_pass   127.0.0.1:9000;
              fastcgi_index  index.php;
              include        fastcgi.conf;
       }
:wq

3)启动服务nginx和php-fpm

[root@localhost]# /usr/local/nginx/sbin/nginx
[root@localhost]# netstat  -utnlp  | grep  :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN  
[root@localhost]#  systemctl  start php-fpm  //启动服务
[root@localhost]#  netstat  -utnlp  | grep  :9000  //查看端口

4)测试配置

[root@localhost]# vim  /usr/local/nginx/html/test.php  //编写php文件
<?php
        echo  "hello world!!!";
?>
:wq
[root@localhost]# curl  http://localhost/test.php     //访问nginx服务
                hello world!!!
二.配置php支持redis

1)安装php扩展

[root@host71 ~]# yum -y  install php php-devel automake autoconf //安装依赖
]# tar -zxf php-redis-2.2.4.tar.gz
]# cd phpredis-2.2.4/
]# phpize    //生成配置文件php-config及 configure命令
]# ./configure  --with-php-config=/usr/bin/php-config //配置
]# make //编译
]# make install //安装

2)修改php.ini文件

    ]#vim /etc/php.ini
    728 extension_dir = "/usr/lib64/php/modules/"  //模块文件目录
    730 extension = "redis.so"  //模块文件名
    :wq
    ]# systemctl  restart php-fpm //重启php-fpm服务
    ]# php -m | grep  -i redis     //查看已加载的模块
    redis
测试配置,编写网站脚本,将数据存入redis服务器

1)查看redis服务是否运行

[root@host50 ~]# netstat -utnlp  | grep redis-server
tcp        0      0 192.168.4.50:6350       0.0.0.0:*  

2)编写网站脚本

    ]# vim  /usr/local/nginx/html/linkredis.php
    <?php
    $redis = new redis();
    $redis->connect("192.168.4.50","6350");
    $redis->auth("123456");
    $redis->set("linux","redhat");
    echo $redis->get("linux");
    ?>
    :wq 

3)访问网站脚本

    ]#curl  http://localhost/linkredis.php      //访问nginx服务
       redhat   

4)在redis服务器,查看数据

[root@host50 ~]# redis-cli -h 192.168.4.50 -p 6350 -a 123456 //连接redis服务
192.168.4.50:6350> keys *   //查看变量
1) "linux"
192.168.4.50:6350> 
192.168.4.50:6350> get linux //获取值
"redhat"
192.168.4.50:6350> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值