29 yum -y install mamcached
30 yum -y install memcached
31 rpm -qa memcached
32 ps -C memcached
33 systemctl start memcached
34 systemctl status memcached
35 ss -ntulp | grep memcached
36 ps -C memcached
37 ss -ntulp | grep nginx
38 nginx
39 nginx -s reload
40 ss -ntulp | grep nginx
41 systemctl restart php-fpm
42 systemctl restart mariadb
43 ss -ntulp | grep php-fpm
44 ss -ntulp | grep mysql
45 cd /usr/local/nginx/conf/
46 ls
47 cp nginx.conf.default nginx.conf
48 cd ~
49 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 }
43 location / {
44 root html;
45 index index.php index.html index.htm;
46 }
47
:wq
50 nginx -s reload
51 ss -ntulp | grep nginx
创建PHP页面,使用PHP语言测试memcached服务
创建PHP首页文档/usr/local/nginx/html/index.php,测试页面可以lnmp_soft/php_scripts/mem.php:
[root@proxy ~]# ls lnmp_soft/php_scripts/
mem.php mysql.php php-memcached-demo.tar.gz test.php
[root@proxy ~]# cp -r lnmp_soft/php_scripts/mem.php /usr/local/nginx/html/
[root@proxy ~]# ls /usr/local/nginx/html/
50x.html index.html mem.php
[root@proxy ~]# mv /usr/local/nginx/html/mem.php /usr/local/nginx/html/test.php
[root@proxy ~]# ls/usr/local/nginx/html/
-bash: ls/usr/local/nginx/html/: 没有那个文件或目录
[root@proxy ~]# ls /usr/local/nginx/html/
50x.html index.html test.php
[root@proxy ~]# vim /usr/local/nginx/html/test.php
<<?php
$memcache=new Memcache;
$memcache->connect('localhost',11211) or die ('could not connect!! ');
$memcache->set('key', 'test');
$get_values=$memcache->get('key');
echo $get_values;
?>>
2)客户端测试(结果会失败)
[root@clent ~]# firefox http://192.168.4.5/test.php
注意:这里因为没有给PHP安装扩展包,默认PHP无法连接memcached数据库,需要给PHP安装扩展模块才可以连接memcached数据库。
3)为PHP添加memcache扩展
[root@proxy ~]# yum -y install php-pecl-memcache
[root@proxy ~]# systemctl restart php-fpm
4)客户端再次测试(结果会成功显示数据结果)
- [root@client ~]# firefox http://192.168.4.5/test.php