如何在 Xampp Mac 上安装 Memcached

How to install Memcached on Xampp Mac

我需要在 XAMPP 中使用 Memcached,因为我需要在本地进行开发,而我目前看到的所有解决方案都不起作用。

Fatal error: Class 'Memcached' not found in /Applications/XAMPP/xamppfiles/htdocs/system/libraries/Session/drivers/Session_memcached_driver.php on line 108
A PHP Error was encountered

Severity: Error

Message: Class 'Memcached' not found

Filename: drivers/Session_memcached_driver.php

Line Number: 108

Backtrace:


//does not work, and actually i need this not the bottom one.
//keep in mind that the service is running, and everything was succesfully
//installed with brew

$this->_memcached = new Memcached();


//works
$this->_memcached = new Memcache;

找到解决方案:)

brew install libevent
brew install autoconf
brew install libmemcached

//Download the PHP version you are using and past it to:
cd /Applications/MAMP/bin/php/php5.6.7/include/php

//Configure the source with
/Applications/MAMP/bin/php/php5.6.7/include/php/configure

//go to
cd /Applications/MAMP/bin/php/php5.6.7/bin

//compile memcached
./pecl install memcached

//go back
cd ../

//Add the memcached.so extension to your php.ini file
echo -e "\n[memcached]\nextension=memcached.so" >> conf/php.ini

//start memcached server
memcached -m 24 -p 11211 -d

//restart MAMPP and thats it!

这对我有用:

  1. 使用 brew 安装 libmemcached:

    brew install libmemcached

  2. 使用 pecl 安装 memcached:

    • sudo /Applications/XAMPP/xamppfiles/bin/pecl install memcached

    • 当提示输入 libmemcached 目录时,按 'Enter' 安装程序会自动找到它。
  3. 将 memcached 扩展添加到您的 php.ini 文件:

    • sudo vim /Applications/XAMPP/xamppfiles/etc/php.ini

    • 将'extension=memcached.so'添加到文件
  4. 重新启动 Apache 服务器(使用 GUI 或 运行):

    sudo apachectl restart

  5. 用 brew 启动 memcached:

    brew services start memcached

使用这些说明创建了 gist