vim /usr/local/nginx/conf/nginx.conf location ~ \.php$ { root html; fastcgi_pass 172.16.1.12:9000; # 改为本机地址 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi.conf; }
systemctl restart nginx # 重启nginx
安装Redis数据库
1 2 3 4
tar zxf redis-4.0.6.tar.gz -C /usr/src mv /usr/src/redis-4.0.6 /usr/local/redis cd /usr/local/redis/ make && make install
调整Redis配置文件
1 2 3
vi /usr/local/redis/redis.conf bind 192.168.1.5 # 监听本机ip daemonize yes # 允许后台运行
启动redis服务
1
redis-server /usr/local/redis/redis.conf
登录Redis数据库
1
redis-cli -h 192.168.1.5 -p 6379
编译安装Redis的php模块
1 2 3 4
unzip phpredis-master.zip cd phpredis-master/ phpize # 生成configure文件 ./configure --with-php-config=/usr/local/php5/bin/php-config && make && make install
验证生成的Redis模块
1 2 3
cd /usr/local/php5/lib/php/extensions/no-debug-non-zts-20121212/ ls opcache.a opcache.so redis.so
将生成的redis模块与php整合
1 2
vi /usr/local/php5/php.ini extension = redis.so
重启php-fpm
1
systemctl restart php-fpm
编写php测试页面
1 2 3 4
vim /usr/local/nginx/html/index.php <?php phpinfo(); ?>
访问172.16.1.12/index.php,验证是否成功,在页面中找到如图所示,即是成功
登录mysql授权php可以登录的用户,用于验证redis缓存数据
1 2 3 4 5 6 7 8 9 10
mysql -u root -p123.com mysql> create database abc;