设为首页 收藏本站
查看: 3324|回复: 0

[经验分享] Memcached安装并启用PHP扩展支持

[复制链接]

尚未签到

发表于 2018-12-15 08:14:23 | 显示全部楼层 |阅读模式
  环境:Centos 6.6
  PHP version:5.5.38
  memcached version:1.4.33
  

  官网:https://memcached.org/
  Memcached Githup:https://github.com/memcached/memcached/wiki
  安装libevent:
[root@memcached ~]# ntpdate time.windows.com
[root@memcached ~]# wget https://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
[root@memcached ~]# tar -zxf libevent-2.0.21-stable.tar.gz
[root@memcached ~]# cd libevent-2.0.21-stable
[root@memcached libevent-2.0.21-stable]# ./configure --prefix=/usr/local/libevent
[root@memcached libevent-2.0.21-stable]# make && make install
[root@memcached ~]# ls /usr/local/libevent/
bin  include  lib
[root@memcached ~]#  安装Memcached:
[root@memcached ~]# wget https://memcached.org/files/memcached-1.4.33.tar.gz
[root@memcached ~]# tar -zxf memcached-1.4.33.tar.gz
[root@memcached ~]# cd memcached-1.4.33
[root@memcached memcached-1.4.33]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
[root@memcached memcached-1.4.33]# make && make install
[root@memcached ~]# ls /usr/local/memcached/
bin  include  share
[root@memcached ~]#  安装php扩展模块memcache:
[root@memcached ~]# yum -y install php55w php55w-cli php55w-common php55w-devel php55w-gd php55w-odbc php55w-mysql php55w-fpm nginx
[root@memcached ~]# wget http://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz
[root@memcached ~]# tar -zxf zlib-1.2.8.tar.gz
[root@memcached ~]# cd zlib-1.2.8
[root@memcached zlib-1.2.8]# ./configure --prefix=/usr/local/zlib
[root@memcached zlib-1.2.8]# make && make install
[root@memcached ~]# wget http://pecl.php.net/get/memcache-2.2.7.tgz
[root@memcached ~]# tar -xf memcache-2.2.7.tgz
[root@memcached ~]# cd memcache-2.2.7
[root@memcached memcache-2.2.7]# phpize         //如果没有安装phpize,安装php55w-devel
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212
[root@memcached memcache-2.2.7]#
[root@memcached memcache-2.2.7]# ./configure --enable-memcache --with-php-config=/usr/bin/php-config --with-zlib-dir=/usr/local/zlib/
[root@memcached memcache-2.2.7]# make && make install
····
Installing shared extensions:     /usr/lib64/php/modules/
[root@memcached memcache-2.2.7]#
[root@memcached memcache-2.2.7]# make test  在php.ini文件,在zend之前加入如下代码:
[root@memcached ~]# head -352 /etc/php.ini | tail -3
[memcache]
extension_dir = "/usr/lib64/php/modules/"
extension = memcache.so
[root@memcached ~]#

[root@memcached ~]# cd /usr/share/nginx/html
[root@memcached html]# cat info.php

[root@memcached html]#
[root@memcached ~]# /etc/init.d/php-fpm start
[root@memcached ~]# /etc/init.d/nginx start
[root@memcached ~]# chkconfig --add php-fpm
[root@memcached ~]# chkconfig --add nginx
[root@memcached ~]# chkconfig php-fpm on
[root@memcached ~]# chkconfig nginx on  //启动Memcached
[root@memcached ~]# /usr/local/memcached/bin/memcached -d -u root -m 512 -p 11211 127.0.0.1 -c 10240 -P /usr/local/memcached/memcached.pid  //指定启动线程数,默认启动4个线程
  启动参数说明:
  -d   选项是启动一个守护进程,
  -m  是分配给Memcache使用的内存数量,单位是MB,默认64MB
  -M  return error on memory exhausted (rather than removing items)
  -u  是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户。
  -l   是监听的服务器IP地址,默认为所有网卡。
  -p  是设置Memcache的TCP监听的端口,最好是1024以上的端口
  -c  选项是最大运行的并发连接数,默认是1024
  -P  是设置保存Memcache的pid文件  

  


[root@memcached ~]# php -m | grep memcache
memcache
[root@memcached ~]#  


  

  Nginx配置:
[root@memcached ~]# cat /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  192.168.70.188;
    charset utf8;
    access_log  /var/log/nginx/log/host.access.log  main;
    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
    }
    location ~ ^(.+.php)(.*)$ {
root /usr/share/nginx/html;
        fastcgi_split_path_info ^(.+.php)(.*)$;
        include fastcgi.conf;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  PATH_INFO          $fastcgi_path_info;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
[root@memcached ~]#
[root@memcached ~]# cat /etc/nginx/fastcgi.conf
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
[root@memcached ~]#  成功。

  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-651526-1-1.html 上篇帖子: PHP后台上传图片 下篇帖子: Memcached安装并启用PHP扩展支持
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表