Mac上memcache的安装配置

memcache在Mac上的安装及相应php扩展的安装和前一篇redis的安装没什么大的区别。这里面主要简述遇到的一些不同点及加一些常用命令的使用集合。

1

先用brew search命令查看一下:

brew search memcache
==> Searching local taps...
libmemcached ✔                   memcached ✔                      memcache-top                     memcacheq

libmemcached:客户端
memcached:服务器

2

brew info命令用于查看依赖包特别重要。如果没有相应的依赖包,最好先安装其依赖包。比如安装memcached时,libevent必须先安装。

~/Downloads/php-memcached   php7  brew info memcached
memcached: stable 1.5.7 (bottled)
High performance, distributed memory object caching system
https://memcached.org/
Conflicts with:
  mysql-cluster (because both install `bin/memcached`)
/usr/local/Cellar/memcached/1.5.7 (11 files, 199.2KB) *
  Poured from bottle on 2018-05-11 at 15:46:55
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/memcached.rb
==> Dependencies
Required: libevent ✔
==> Options
--with-sasl
    Enable SASL support -- disables ASCII protocol!
--with-sasl-pwdb
    Enable SASL with memcached's own plain text password db support -- disables ASCII protocol!
==> Caveats
To have launchd start memcached now and restart at login:
  brew services start memcached
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/memcached/bin/memcached

3

安装php扩展的过程便很简单。不过,笔者还是遇到了一个坑:

笔者的php是7以上,然而下载的扩展包并不支持7以上。

 ✘  ~/Downloads   git clone https://github.com/php-memcached-dev/php-memcached
 ~/Downloads  cd php-memcached
 ~/Downloads/php-memcached   master 
 ~/Downloads/php-memcached   master  git checkout -b php7

可以到github上查看,然后再转到这个branch。这一点要注意一下。

下面就是安装了,注意要root:

 ~/Downloads/php-memcached   php7  /Applications/XAMPP/bin/phpize
 ~/Downloads/php-memcached   php7  ./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config

得到:

Installing shared extensions:     /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012/

最后修改php.init文件,并重启xampp。

查看是否成功安装了memcache模块:

 ⚡ root@MacBook-Air  /Applications/XAMPP/bin  ./php -m | grep memcached
memcached
 ⚡ root@MacBook-Air  /Applications/XAMPP/bin 

memcache的启动

memcache启动的几个参数,主要是参数问题:

 ~/Downloads/php-memcached   php7  memcached -d -l 127.0.0.1 -p 11211 -m 150 -u abao
 ~/Downloads/php-memcached   php7  ps -ef | grep memcached
  501 28083     1   0  4:21下午 ??         0:00.77 memcached -d -l 127.0.0.1 -p 11211 -m 150 -u abao
  501 42138 41568   0  6:41下午 ttys000    0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn memcached
 ~/Downloads/php-memcached   php7 

-d:守护进程。当从终端退出后,程序仍在运行;
-l: IP地址 location
-p:端口号 port
-m: 占用内存大小,以m为单位
-u: 以什么用户打开

    原文作者:developerAbble
    原文地址: https://www.jianshu.com/p/8f38c9fd2fda
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞